public void RemoveOneElementFromCollection_WhenValitEntityIsPassed()
        {
            // Arrange
            var carAdsServices = new CarAdServices(
                this.carAdsRepoMock.Object,
                this.carBrandsRepoMock,
                this.carModelsRepoMock,
                this.carFeatureServicesMock,
                this.unitOfWorkMocked.Object);

            var countBeforeDelete = carAds.Count();

            var carAdsAllAsEnumerable = carAds.ToList();

            this.carAdsRepoMock.Setup(x => x.Delete(It.IsAny <CarAd>()))
            .Callback(() =>
            {
                carAdsAllAsEnumerable.Remove(carAds.ToList().First());
            });

            // Act
            carAdsServices.DeleteAd(It.IsAny <Guid>());

            var countAfterDelete = carAdsAllAsEnumerable.Count();

            // Assert
            Assert.AreEqual(countBeforeDelete - 1, countAfterDelete);
        }
        public void ReturnTownServiceInstance_WhenCorrectDataIsPassed()
        {
            // Act
            var newCarAdServiceInstance = new CarAdServices(
                this.carAdsRepoMock,
                this.carBrandsRepoMock,
                this.carModelsRepoMock,
                this.carFeatureServicesMock,
                this.unitOfWorkMocked);

            // Assert
            Assert.IsInstanceOf <ICarAdServices>(newCarAdServiceInstance);
        }
        public void Call_GetAllCarFeatures_FromCarFeatureServicesOnce()
        {
            // Arrange
            var carAdsServices = new CarAdServices(
                this.carAdsRepoMock.Object,
                this.carBrandsRepoMock,
                this.carModelsRepoMock,
                this.carFeatureServicesMock.Object,
                this.unitOfWorkMocked.Object);

            var firstCarFeature = new CarFeature {
                Name = "Klima!"
            };
            var secondCarFeature = new CarFeature {
                Name = "Windows!"
            };

            var carFeatures = new List <CarFeature>
            {
                firstCarFeature,
                secondCarFeature
            };

            var carFeaturesIds = new List <string>
            {
                firstCarFeature.Id.ToString(),
                secondCarFeature.Id.ToString(),
            };

            this.carFeatureServicesMock.Setup(x => x.GetAllCarFeatures()).Returns(carFeatures.AsQueryable());

            // Act
            carAdsServices.AddNewCarAd(
                It.IsAny <string>(),
                It.IsAny <Guid>(),
                It.IsAny <CarType>(),
                It.IsAny <int>(),
                It.IsAny <int>(),
                It.IsAny <FuelType>(),
                It.IsAny <TransmissionType>(),
                carFeaturesIds,
                It.IsAny <Guid>(),
                It.IsAny <double>(),
                It.IsAny <string>(),
                It.IsAny <string>(),
                It.IsAny <string>());

            // Assert
            this.carFeatureServicesMock.Verify(x => x.GetAllCarFeatures(), Times.Once);
        }
Esempio n. 4
0
        public void Call_AllMethodFromRepositoryOnce()
        {
            // Arrange
            var carAdsServices = new CarAdServices(
                this.carAdsRepoMock.Object,
                this.carBrandsRepoMock,
                this.carModelsRepoMock,
                this.carFeatureServicesMock,
                this.unitOfWorkMocked);

            // Act
            carAdsServices.GetAll();

            // Assert
            this.carAdsRepoMock.Verify(x => x.All, Times.Once);
        }
Esempio n. 5
0
        public void ReturnInstanceOfQuarable_WithValidaDataIsPassed()
        {
            // Arrange
            var carAdsServices = new CarAdServices(
                this.carAdsRepoMock.Object,
                this.carBrandsRepoMock,
                this.carModelsRepoMock,
                this.carFeatureServicesMock,
                this.unitOfWorkMocked);

            // Act
            var allCarAds = carAdsServices.GetAll();

            // Assert
            Assert.IsInstanceOf <IQueryable <CarAd> >(allCarAds);
        }
Esempio n. 6
0
        public void ReturnQueryable_WithExactNumberOfCarAds()
        {
            // Arrange
            var carAdsServices = new CarAdServices(
                this.carAdsRepoMock.Object,
                this.carBrandsRepoMock,
                this.carModelsRepoMock,
                this.carFeatureServicesMock,
                this.unitOfWorkMocked);

            // Act
            var allCarAdsCount = carAdsServices.GetAll().Count();

            // Assert
            Assert.AreEqual(allCarAdsCount, this.carAds.Count());
        }
Esempio n. 7
0
        public void ReturnCarAd_WithExactSameId()
        {
            // Arrange
            var carAdsServices = new CarAdServices(
                this.carAdsRepoMock.Object,
                this.carBrandsRepoMock,
                this.carModelsRepoMock,
                this.carFeatureServicesMock,
                this.unitOfWorkMocked);

            // Act
            var actualReturnedCarAd = carAdsServices.GetAdById(this.expectedCarAd.Id);

            // Assert
            Assert.AreSame(this.expectedCarAd, actualReturnedCarAd);
        }
        public void ReturnQueryable_WithExactlyFourOfCarAds()
        {
            // Arrange
            var carAdsServices = new CarAdServices(
                this.carAdsRepoMock.Object,
                this.carBrandsRepoMock,
                this.carModelsRepoMock,
                this.carFeatureServicesMock,
                this.unitOfWorkMocked);

            // Act
            var exactlyFourCarAdsResult = carAdsServices.GetLastFiveAddedAds().Count();

            // Assert
            Assert.AreEqual(4, exactlyFourCarAdsResult);
        }
        public void Call_CommitFromUnitOfWorkOnce()
        {
            // Arrange
            var carAdsServices = new CarAdServices(
                this.carAdsRepoMock.Object,
                this.carBrandsRepoMock,
                this.carModelsRepoMock,
                this.carFeatureServicesMock,
                this.unitOfWorkMocked.Object);

            // Act
            carAdsServices.DeleteAd(It.IsAny <Guid>());

            // Assert
            this.unitOfWorkMocked.Verify(x => x.Commit(), Times.Once);
        }
Esempio n. 10
0
        public void Call_GetByIdMethodFromRepositoryOnce()
        {
            // Arrange
            var carAdsServices = new CarAdServices(
                this.carAdsRepoMock.Object,
                this.carBrandsRepoMock,
                this.carModelsRepoMock,
                this.carFeatureServicesMock,
                this.unitOfWorkMocked.Object);

            // Act
            carAdsServices.DeleteAd(It.IsAny <Guid>());

            // Assert
            this.carAdsRepoMock.Verify(x => x.GetById(It.IsAny <Guid>()), Times.Once);
        }