public void Verify_Deactivate_ByID_ANonExistingEntity_Should_ThrowAnInvalidOperationException() { // Arrange var mockResourceTypesRepository = ResourceTypesMockingSetup.DoMockingSetupForRepository(); mockResourceTypesRepository.Setup(m => m.Get(It.IsAny<int>())).Returns(() => null); var mockResourceTypesMapper = new Mock<IResourceTypeMapper>(); mockResourceTypesMapper.Setup(m => m.AreEqual(It.IsAny<IResourceTypeModel>(), It.IsAny<IResourceType>())).Returns(() => true); var businessWorkflow = new ResourceTypesBusinessWorkflow(mockResourceTypesRepository.Object, mockResourceTypesMapper.Object); // Act/Assert Assert.Throws<System.InvalidOperationException>(() => businessWorkflow.Deactivate(1)); }
public void Verify_Deactivate_ByKey_ANonExistingEntity_Should_ThrowAnInvalidOperationException() { // Arrange var mockResourceTypesRepository = ResourceTypesMockingSetup.DoMockingSetupForRepository(); mockResourceTypesRepository.Setup(m => m.Get(It.IsAny <string>())).Returns(() => null); var mockResourceTypesMapper = new Mock <IResourceTypeMapper>(); mockResourceTypesMapper.Setup(m => m.AreEqual(It.IsAny <IResourceTypeModel>(), It.IsAny <IResourceType>())).Returns(() => true); var businessWorkflow = new ResourceTypesBusinessWorkflow(mockResourceTypesRepository.Object, mockResourceTypesMapper.Object); // Act/Assert Assert.Throws <System.InvalidOperationException>(() => businessWorkflow.Deactivate("TEST")); }
public void Verify_Deactivate_ByKey_Should_DeactivateTheObjectAndReturnTrue() { // Arrange var mockResourceTypesRepository = ResourceTypesMockingSetup.DoMockingSetupForRepository(); var mockResourceTypesMapper = new Mock <IResourceTypeMapper>(); mockResourceTypesMapper.Setup(m => m.AreEqual(It.IsAny <IResourceTypeModel>(), It.IsAny <IResourceType>())).Returns(() => true); var businessWorkflow = new ResourceTypesBusinessWorkflow(mockResourceTypesRepository.Object, mockResourceTypesMapper.Object); mockResourceTypesRepository.Setup(m => m.Get(It.IsAny <string>())).Returns(() => new Mock <IResourceType>().Object); mockResourceTypesRepository.Setup(m => m.SaveChanges()).Returns(() => true); // Act var result = businessWorkflow.Deactivate("KING-STEPHEN"); // Assert mockResourceTypesRepository.Verify(m => m.Deactivate(It.IsAny <IResourceType>()), Times.Once); Assert.Equal(true, result); }
public void Verify_Deactivate_ByID_Should_DeactivateTheObjectAndReturnTrue() { // Arrange var mockResourceTypesRepository = ResourceTypesMockingSetup.DoMockingSetupForRepository(); var mockResourceTypesMapper = new Mock<IResourceTypeMapper>(); mockResourceTypesMapper.Setup(m => m.AreEqual(It.IsAny<IResourceTypeModel>(), It.IsAny<IResourceType>())).Returns(() => true); var businessWorkflow = new ResourceTypesBusinessWorkflow(mockResourceTypesRepository.Object, mockResourceTypesMapper.Object); mockResourceTypesRepository.Setup(m => m.Get(It.IsAny<int>())).Returns(() => new Mock<IResourceType>().Object); mockResourceTypesRepository.Setup(m => m.SaveChanges()).Returns(() => true); // Act var result = businessWorkflow.Deactivate(1); // Assert mockResourceTypesRepository.Verify(m => m.Deactivate(It.IsAny<IResourceType>()), Times.Once); Assert.Equal(true, result); }