public void InvalidUpdateOnderhoudsopdrachtPutTest() { // Arrange var onderhoudsopdrachtServiceMock = new Mock <IOnderhoudsopdrachtService>(MockBehavior.Strict); onderhoudsopdrachtServiceMock.Setup(x => x.UpdateOnderhoudsopdracht(It.IsAny <UpdateOnderhoudCommand>())); var logServiceMock = new Mock <ILogService>(MockBehavior.Strict); logServiceMock.Setup(x => x.Log(It.IsAny <LogMessage>())); logServiceMock.Setup(x => x.LogException(It.IsAny <LogMessage>())); var controller = new OnderhoudController(onderhoudsopdrachtServiceMock.Object, logServiceMock.Object); controller.ModelState.AddModelError("error", "testerror"); // Act var result = controller.Put(new UpdateOnderhoudCommand()); // Assert onderhoudsopdrachtServiceMock.Verify(x => x.UpdateOnderhoudsopdracht(It.IsAny <UpdateOnderhoudCommand>()), Times.Never()); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult)); var invalidRequest = (result as BadRequestObjectResult).Value as InvalidRequest; Assert.AreEqual("Request bevat: 1 fouten", invalidRequest.Message); logServiceMock.Verify(x => x.Log(It.IsAny <LogMessage>()), Times.Once()); logServiceMock.Verify(x => x.LogException(It.IsAny <LogMessage>()), Times.Never()); }
public void ValidUpdateOnderhoudsopdrachtPutDomainServiceExceptionTest() { // Arrange var onderhoudsopdrachtServiceMock = new Mock <IOnderhoudsopdrachtService>(MockBehavior.Strict); onderhoudsopdrachtServiceMock.Setup(x => x.UpdateOnderhoudsopdracht(It.IsAny <UpdateOnderhoudCommand>())).Throws <Exception>(); var logServiceMock = new Mock <ILogService>(MockBehavior.Strict); logServiceMock.Setup(x => x.Log(It.IsAny <LogMessage>())); logServiceMock.Setup(x => x.LogException(It.IsAny <LogMessage>())); var controller = new OnderhoudController(onderhoudsopdrachtServiceMock.Object, logServiceMock.Object); // Act var result = controller.Put(new UpdateOnderhoudCommand()); // Assert onderhoudsopdrachtServiceMock.Verify(x => x.UpdateOnderhoudsopdracht(It.IsAny <UpdateOnderhoudCommand>()), Times.Once()); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult)); var invalidRequest = (result as BadRequestObjectResult).Value as InvalidRequest; Assert.AreEqual("Er ging iets mis. Onderhoud niet geupdated.", invalidRequest.Message); Assert.AreEqual(0, invalidRequest.InvalidProperties.Count()); logServiceMock.Verify(x => x.Log(It.IsAny <LogMessage>()), Times.Never()); logServiceMock.Verify(x => x.LogException(It.IsAny <LogMessage>()), Times.Once()); }
public void ValidUpdateOnderhoudsopdrachtPutTest() { // Arrange var logServiceMock = new Mock <ILogService>(MockBehavior.Strict); logServiceMock.Setup(x => x.Log(It.IsAny <LogMessage>())); logServiceMock.Setup(x => x.LogException(It.IsAny <LogMessage>())); var onderhoudsopdrachtServiceMock = new Mock <IOnderhoudsopdrachtService>(MockBehavior.Strict); onderhoudsopdrachtServiceMock.Setup(x => x.UpdateOnderhoudsopdracht(It.IsAny <UpdateOnderhoudCommand>())); var controller = new OnderhoudController(onderhoudsopdrachtServiceMock.Object, logServiceMock.Object); // Act var result = controller.Put(new UpdateOnderhoudCommand()); // Assert onderhoudsopdrachtServiceMock.Verify(x => x.UpdateOnderhoudsopdracht(It.IsAny <UpdateOnderhoudCommand>()), Times.Once()); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(OkResult)); logServiceMock.Verify(x => x.Log(It.IsAny <LogMessage>()), Times.Never()); logServiceMock.Verify(x => x.LogException(It.IsAny <LogMessage>()), Times.Never()); }