Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Tests and Postal hybrid MVC5 + Web Api 2 #149

Open
ToXinE opened this issue Mar 22, 2016 · 0 comments
Open

Unit Tests and Postal hybrid MVC5 + Web Api 2 #149

ToXinE opened this issue Mar 22, 2016 · 0 comments

Comments

@ToXinE
Copy link

ToXinE commented Mar 22, 2016

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> 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> 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 = "[email protected]";
                            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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant