public void Verify_Create_Should_AddANewEntityObjectToTheDatabase()
 {
     // Arrange
     var mockLocationsRepository = LocationsMockingSetup.DoMockingSetupForRepository();
     mockLocationsRepository.Setup(m => m.Search(It.IsAny<ILocationSearchModel>(), It.IsAny<bool>()))
         .Returns(() => new Mock<List<ILocation>>().Object);
     var businessWorkflow = new LocationsBusinessWorkflow(mockLocationsRepository.Object, new LocationMapper());
     var model = LocationsMockingSetup.DoMockingSetupForLocationModel();
     // Act
     try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ }
     // Assert
     mockLocationsRepository.Verify(m => m.Add(It.IsAny<ILocation>()), Times.Once);
 }
Ejemplo n.º 2
0
        public void Verify_Create_Should_AddANewEntityObjectToTheDatabase()
        {
            // Arrange
            var mockLocationsRepository = LocationsMockingSetup.DoMockingSetupForRepository();

            mockLocationsRepository.Setup(m => m.Search(It.IsAny <ILocationSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new Mock <List <ILocation> >().Object);
            var businessWorkflow = new LocationsBusinessWorkflow(mockLocationsRepository.Object, new LocationMapper());
            var model            = LocationsMockingSetup.DoMockingSetupForLocationModel();

            // Act
            try { businessWorkflow.Create(model.Object); } catch { /* Ignored */ }
            // Assert
            mockLocationsRepository.Verify(m => m.Add(It.IsAny <ILocation>()), Times.Once);
        }
 public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal()
 {
     // Arrange
     var mockLocationsRepository = LocationsMockingSetup.DoMockingSetupForRepository();
     var mockLocation = LocationsMockingSetup.DoMockingSetupForLocation(1);
     mockLocationsRepository.Setup(m => m.Search(It.IsAny<ILocationSearchModel>(), It.IsAny<bool>()))
         .Returns(() => new List<ILocation> { mockLocation.Object } );
     mockLocationsRepository.Setup(m => m.Get(It.IsAny<int>())).Returns(() => mockLocation.Object);
     var businessWorkflow = new LocationsBusinessWorkflow(mockLocationsRepository.Object, new LocationMapper());
     var model = LocationsMockingSetup.DoMockingSetupForLocationModel();
     // Act
     try { businessWorkflow.Create(model.Object); }
     catch { /* ignored, the Get call at the end doesn't work because don't get a real entity with id on it */ }
     // Assert
     mockLocationsRepository.Verify(m => m.Add(It.IsAny<ILocation>()), Times.Never);
 }
Ejemplo n.º 4
0
        public void Verify_Create_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var mockLocationsRepository = LocationsMockingSetup.DoMockingSetupForRepository();
            var mockLocation            = LocationsMockingSetup.DoMockingSetupForLocation(1);

            mockLocationsRepository.Setup(m => m.Search(It.IsAny <ILocationSearchModel>(), It.IsAny <bool>()))
            .Returns(() => new List <ILocation> {
                mockLocation.Object
            });
            mockLocationsRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => mockLocation.Object);
            var businessWorkflow = new LocationsBusinessWorkflow(mockLocationsRepository.Object, new LocationMapper());
            var model            = LocationsMockingSetup.DoMockingSetupForLocationModel();

            // Act
            try { businessWorkflow.Create(model.Object); }
            catch { /* ignored, the Get call at the end doesn't work because don't get a real entity with id on it */ }
            // Assert
            mockLocationsRepository.Verify(m => m.Add(It.IsAny <ILocation>()), Times.Never);
        }