Exemple #1
0
        public void ErrorsController_Post_Roundtrip()
        {
            var errorReport = new ErrorReport
            {
                AppId                = "apps/1",
                Category             = "category",
                Detail               = "detail",
                Message              = "message",
                Source               = "source",
                ReportedTimestampUtc = DateTime.UtcNow,
                UserEmail            = "*****@*****.**"
            };

            var mockErrorService = new Mock <IErrorService>();

            mockErrorService
            .Setup(
                s => s.ReportError(It.IsAny <ErrorReport>(), "api-key"))
            .Returns(errorReport);

            var controller = new ErrorsController(mockErrorService.Object);

            WebApiControllerHelper.MakeTestable(controller, "errors");

            var response          = controller.Post(errorReport, "api-key");
            var responseErrorTask = response.Content.ReadAsAsync <ErrorReport>();

            responseErrorTask.Wait();
            var responseError = responseErrorTask.Result;

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            Assert.AreEqual("apps/1", responseError.AppId);
        }
Exemple #2
0
        public void HomeRender_Post_Create_Success()
        {
            // Arrange

            var testModel = new AppModel
            {
                Name          = "App Name",
                ContactEmails = { "*****@*****.**", "*****@*****.**" }
            };

            var mockAppService = new Mock <IAppService>();

            mockAppService
            .Setup(service => service.CreateApp(testModel))
            .Returns(() => new AppModel
            {
                Id            = "apps/1",
                Name          = "App Name",
                ContactEmails = { "*****@*****.**", "*****@*****.**" },
                ApiKey        = "apiKey"
            });

            var appsController = new AppsController(mockAppService.Object);

            WebApiControllerHelper.MakeTestable(appsController, "apps");
            // Act

            var response = appsController.Post(testModel);
            //WebViewPage<AppModel> complete = new ErrorGun.Web.Views.App.Complete();
            //var doc = complete.RenderAsHtml((AppModel) response.Content.ReadAsStringAsync());

            //// Assert

            //var h1 = doc.DocumentNode.SelectSingleNode("//h1");
            //Assert.AreEqual("App Created", h1.InnerHtml.Trim());

            // TODO: assert model properties correctly rendered
        }