andrewdavey / andrewdavey/postal

Unit Tests and Postal hybrid MVC5 + Web Api 2

Offen
#149 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C#
Sterne
534
Forks
164
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I have an issue during Unit testing.
I have an hybrid MVC5 + Web API2 web application running in .NET framework 4.5.1

I have a Web Api that send a mail from users linked to a fileid.

```
[HttpGet]
[ResponseType(typeof(HttpStatusCode))]
public HttpResponseMessage ResendMailSign(HttpRequestMessage request, int fileId)
{
try
{
using (var db = CtxFactory.Create)
{
List status = db.status.Where(x=>x.fileid == fileId).DistinctBy(x=>x.userid).ToList();
SendMemeSiMailNull(status);
}
}
catch (Exception ex)
{
return request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
}
return request.CreateResponse(HttpStatusCode.OK);
}
```

My Method that send mail SendMemeSiMailNull

```
private void SendMemeSiMailNull(List status)
{
try
{
using (var db = CtxFactory.Create)
{
foreach (var target in status)
{
var cClient = db.Client.SingleOrDefault(cli => cli.AspNetUsers_Id == target.userid);
if (cClient != null)
{
dynamic email = new DocWaitingSignEmail("DocWaitingSign");
email.From = ConfigurationManager.AppSettings["SmtpSign"];
email.To = cClient.Mail;
email.Bcc = "no-reply@mydomain.com";
email.Subject = "Subject";
email.Message = "f00bar";
email.SignKey = cClient.Token;
email.EsignUrl = string.Format(Paths.EsignMethodDoSign, "");
email.Oururl = Paths.Protocol + Paths.BaseUrl + Paths.ApplicationPath;
email.Send();
}
}
}
}
catch
{
throw;
}
return;
}
```

the "Postal" Class

```
using Postal;
using System;
using System.Collections.Generic;
using System.Web;

public class DocWaitingSignEmail : Email
{
public DocWaitingSignEmail() : base() { }
public DocWaitingSignEmail(String Name) : base(Name) { }

public string Message { get; set; }
public string SignKey { get; set; }
}

```

this method is tested by

```
[TestMethod]
public void ResendMail_5048()
{
var req = VerbRequestMessage("api/ESignature/ResendMailSign", HttpMethod.Get);
var r = GetControllerAs("myuserlogin").ResendMailSign(req, 5048);
Console.WriteLine(r.StatusCode);
Assert.IsTrue(r.IsSuccessStatusCode, "IsSuccessStatusCode == false");
}
```

It seems like MS Unit Testing is not supported by Postal because it always throw an exception : at line `email.Send();` of `SendMemeSiMailNull`

`Value cannot be null : httpBrowserCapabilities`

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.