Example #1
0
        public void SendApkAanvraagWithErrorsReturnsViewResult()
        {
            var webConfigMock = new Mock <IOptions <WebAppConfig> >(MockBehavior.Strict);
            // Arrange
            var loggerMock = new Mock <ILogService>(MockBehavior.Strict);

            loggerMock.Setup(x => x.Log(It.IsAny <LogMessage>()));
            loggerMock.Setup(x => x.LogException(It.IsAny <LogMessage>()));

            using (var repo = new OnderhoudsopdrachtenRepository(new GarageAdministratieContext(_options)))
            {
                var target = new ApkController(_rdwIntegrationServiceAgent, repo, loggerMock.Object, webConfigMock.Object);

                target.ModelState.AddModelError("error", "custom error");
                var model = new ApkAanvraagViewModel();
                model.EigenaarAuto = "Max";

                // Act
                var result = target.SendApkAanvraag(model);

                // Assert
                Assert.IsNotNull(result);
                Assert.IsNotNull((result as ViewResult).Model);
                Assert.AreEqual(model.EigenaarAuto, ((result as ViewResult).Model as ApkAanvraagViewModel).EigenaarAuto);

                loggerMock.Verify(x => x.Log(It.IsAny <LogMessage>()), Times.Never());
                loggerMock.Verify(x => x.LogException(It.IsAny <LogMessage>()), Times.Never());
            }
        }
Example #2
0
        public void SendApkAanvraagFailingAgentMessageResult()
        {
            var webConfigMock = new Mock <IOptions <WebAppConfig> >(MockBehavior.Strict);

            webConfigMock.Setup(x => x.Value).Returns(new WebAppConfig());

            // Arrange
            var loggerMock = new Mock <ILogService>(MockBehavior.Strict);

            loggerMock.Setup(x => x.Log(It.IsAny <LogMessage>()));
            loggerMock.Setup(x => x.LogException(It.IsAny <LogMessage>()));

            using (var repo = new OnderhoudsopdrachtenRepository(new GarageAdministratieContext(_options)))
            {
                var target = new ApkController(_rdwIntegrationServiceExceptionAgent, repo, loggerMock.Object, webConfigMock.Object);

                var model = new ApkAanvraagViewModel();
                model.EigenaarAuto = "Max";

                // Act
                var result = target.SendApkAanvraag(model);

                // Assert
                Assert.IsNotNull(result);
                Assert.IsNotNull((result as ViewResult).Model);
                Assert.IsNotNull(target.ViewData["FeedbackMessage"]);
                Assert.AreEqual((string)target.ViewData["FeedbackMessage"], "Sorry, de service is op dit niet beschikbaar. Probeer het later opnieuw.");
                Assert.AreEqual(model.EigenaarAuto, ((result as ViewResult).Model as ApkAanvraagViewModel).EigenaarAuto);

                loggerMock.Verify(x => x.Log(It.IsAny <LogMessage>()), Times.Never());
                loggerMock.Verify(x => x.LogException(It.IsAny <LogMessage>()), Times.Once());
            }
        }