Пример #1
0
        public void TestUpdateAsync()
        {
            AutoMapperConfiguration.Config();

            var countryRepository = new Mock <IRepository <Country> >();
            var mockService       = new Mock <IUnitOfWork>();

            var dbSet = new FakeDbSet <Country>();

            dbSet.AddRange(FakeCountries.FakeDataCountries());

            countryRepository.Setup(x => x.FindByAsync(1))
            .Returns(dbSet.FindAsync(new CancellationToken(false), 1));

            var countryDto = FakeCountries.FakeDataCountriesDto(hasKiosks: false).FirstOrDefault();

            mockService.Setup(x => x.Countries).Returns(countryRepository.Object);

            mockService.Setup(x => x.CommitAsync()).Returns(Task.FromResult(0)).Verifiable();

            //var countryService = new CountryService(mockService.Object);

            //var subsites = countryService.UpdateAsync(countryDto).Result;

            //mockService.Verify(x => x.CommitAsync(), Times.Once);
        }
        protected FakeDbSet <T> Set <T>(params T[] items)
            where T : class
        {
            var set = new FakeDbSet <T>();

            set.AddRange(items);
            return(set);
        }
        public void AsEnumerable()
        {
            _dbSet.AddRange(_list);
            var result = _dbSet.AsEnumerable();

            Assert.AreEqual(2, result.Count());
        }
Пример #4
0
        public void AddRange_WithItems_ShouldAddItemsToSourceList()
        {
            var data = new List <Person>();
            var sut  = new FakeDbSet <Person>(data);

            var itemsToAdd = new[] { new Person(), new Person() };
            var result     = sut.AddRange(itemsToAdd);

            Assert.That(itemsToAdd, Is.SubsetOf(data));
            Assert.That(result, Is.EquivalentTo(itemsToAdd));
        }
Пример #5
0
        public void TestFindAllAsync()
        {
            AutoMapperConfiguration.Config();

            var dbSet = new FakeDbSet <Country>();

            dbSet.AddRange(FakeCountries.FakeDataCountries());

            var countryRepository = new Mock <IRepository <Country> >();
            var mockService       = new Mock <IUnitOfWork>();

            mockService.Setup(x => x.Countries).Returns(countryRepository.Object);
            mockService.Setup(x => x.Countries.FindAll(null)).Returns(dbSet);

            //var countryService = new CountryService(mockService.Object);
            //var subsites = countryService.FindAllAsync().Result;
        }
Пример #6
0
        public MovieContextTests()
        {
            //Create TestServer
            var builder = new WebHostBuilder()
                          .UseStartup <Startup>();

            //testserver to initialize connectionstring
            server = new TestServer(builder);

            contextmock = new Mock <IMoviesContext>();
            MovieDbSet  = new FakeDbSet <Movie>();
            MovieDbSet.AddRange(new[]
            {
                new Movie(1, "Shrek", DateTime.Now, 2000, 67),
                new Movie(2, "Shrek 2", DateTime.Now, 1500, 64),
                new Movie(3, "Shrek 3", DateTime.Now, 1000, 62)
            });
        }
Пример #7
0
        public ReviewContextTests()
        {
            //Create TestServer
            var builder = new WebHostBuilder()
                          .UseStartup <Startup>();

            //testserver to initialize connectionstring
            server = new TestServer(builder);

            contextmock = new Mock <IReviewContext>();

            ReviewDbSet = new FakeDbSet <Review>();

            ReviewDbSet.AddRange(new[]
            {
                new Review(DateTime.Now, "Nice movie", "Rick", 4),
                new Review(DateTime.Now, "Cool movie", "Olaf", 5)
            });

            account = new Account
            {
                Name = "Simon"
            };
        }
Пример #8
0
        public AccountContextTests()
        {
            //Create TestServer
            var builder = new WebHostBuilder()
                          .UseStartup <Startup>();

            //testserver to initialize connectionstring
            server = new TestServer(builder);

            contextmock = new Mock <IAccountContext>();
            ReviewDbSet = new FakeDbSet <Review>();

            account = new Account
            {
                Name     = "Simon",
                Password = "******"
            };

            ReviewDbSet.AddRange(new[]
            {
                new Review(DateTime.Now, "Nice Movie", "Pieter", 4),
                new Review(DateTime.Now, "Excellent Movie", "Sjors", 5)
            });
        }