コード例 #1
0
        public void ProductRepository_GetAllValues()
        {
            Mock <IDatabaseConnectionFactory> connectionFactoryMock = new Mock <IDatabaseConnectionFactory>();

            var products = new List <Product>
            {
                new Product {
                    BrandId = 1, Description = "açıklama", DiscountPrice = 10, Name = "test ürünü", Price = 100, Quantitiy = 1, Status = true, Id = 1
                }
            };

            var brands = new List <Brands>
            {
                new Brands {
                    Name = "Marka1", Status = true, Id = 1
                }
            };

            var db = new InMemoryDatabase();

            db.Insert(products);
            db.Insert(brands);

            connectionFactoryMock.Setup(c => c.GetConnection()).Returns(db.OpenConnection());
            var result = new ProductRepository(connectionFactoryMock.Object).GetAllValues();

            Assert.AreEqual(1, result.Count());
        }
コード例 #2
0
        public async Task GetAllAsync_ShouldReturnElements()
        {
            // Arrange
            var sites = new List <Sites>
            {
                new Sites
                {
                    Id = 1
                },
                new Sites
                {
                    Id = 2
                }
            };
            var db = new InMemoryDatabase();

            db.Insert(sites);
            var connectionFactoryMock = new Mock <IDatabaseConnectionFactory>();

            connectionFactoryMock.Setup(c => c.GetConnection()).Returns(db.OpenConnection());

            // Act
            var result = await new SitesRepository(connectionFactoryMock.Object).GetAllAsync();

            // Assert
            Assert.Equal(sites, result.ToList());
        }
コード例 #3
0
        public async Task test_get_widgets_ormlite()
        {
            //
            //    Mock data
            var table = new Widget
            {
                WidgetId   = 1,
                WidgetName = "test hell homer"
            };
            var table2 = new Widget
            {
                WidgetId   = 2,
                WidgetName = "test hell homer the second"
            };
            var db = new InMemoryDatabase();

            db.OpenConnection();
            db.Insert(new List <Widget> {
                table, table2
            });

            //
            //    Test
            var repository = CreateMockRepository(db);
            var result     = await repository.GetWidgets();

//            Assert.Single(result);
            Assert.Equal(2, result.Count());
        }
コード例 #4
0
        public void should_retrieve_all_posts()
        {
            // Arrange
            var mockPosts = PostsHelper.GetDefaultMockData();
            var db        = new InMemoryDatabase();

            db.Insert <Post>(mockPosts);
            _connectionFactory.GetConnection().Returns(db.OpenConnection());

            // Act
            var posts     = _sut.GetAll();
            var postsList = posts.ToList();

            // Assert
            Assert.IsNotNull(posts);
            Assert.AreEqual(posts.Count(), mockPosts.Count);

            mockPosts = mockPosts.OrderBy(o => o.Id).ToList();
            postsList = postsList.OrderBy(o => o.Id).ToList();

            for (var i = 0; i < mockPosts.Count; i++)
            {
                var mockPost = mockPosts[0];
                var post     = postsList[0];
                Assert.IsTrue(mockPost.Id == post.Id);
                Assert.IsTrue(mockPost.Title == post.Title);
                Assert.IsTrue(mockPost.Text == post.Text);
            }
        }
コード例 #5
0
        protected RepositoryTests(IEnumerable <T> objects)
        {
            var fakeDatabase = new InMemoryDatabase();

            fakeDatabase.Insert(objects);

            this.Context = Substitute.For <IDatabaseContext>();
            this.Context.Connection.Returns(fakeDatabase.OpenConnection());
        }
コード例 #6
0
        public PeopleRepositoryTests()
        {
            connectionService = new Mock <IConnection>();

            var db = new InMemoryDatabase();

            db.Insert(people);
            connectionService.Setup(c => c.GetConnection(configuration)).Returns(db.OpenConnection());

            peopleGateway = new PeopleRepository(connectionService.Object, configuration);
        }
コード例 #7
0
        public void TestConfigWorks()
        {
            var config = new TestConfiguration();

            using (var session = new InMemoryDatabase(config).BeginSession()) {
                session.Insert(new Post()
                {
                    Title = "Foo"
                });
                Assert.Equal("Foo", session.Get <Post>(1).Title);
            }
        }
コード例 #8
0
        public void should_retrieve_no_one_post()
        {
            // Arrange
            var mockPosts = PostsHelper.GetDefaultMockData();
            var db        = new InMemoryDatabase();

            db.Insert <Post>(mockPosts);
            _connectionFactory.GetConnection().Returns(db.OpenConnection());

            // Act
            var post = _sut.GetById(1000);

            // Assert
            Assert.IsNull(post);
        }
コード例 #9
0
        public void should_retrieve_post_by_id(int id)
        {
            // Arrange
            var mockPosts = PostsHelper.GetDefaultMockData();
            var db        = new InMemoryDatabase();

            db.Insert <Post>(mockPosts);
            _connectionFactory.GetConnection().Returns(db.OpenConnection());

            var mockPost = mockPosts.Where(x => x.Id == id).FirstOrDefault();

            // Act
            var post = _sut.GetById(id);

            // Assert
            Assert.IsNotNull(post);

            Assert.IsTrue(mockPost.Id == post.Id);
            Assert.IsTrue(mockPost.Title == post.Title);
            Assert.IsTrue(mockPost.Text == post.Text);
        }
コード例 #10
0
        public async Task UpdateProduct_When_ProductIsModified()
        {
            // Arrange
            var products = new List <Product>
            {
                new Product {
                    Id = 1, Name = "Product1", Description = "This is the first product"
                },
                new Product {
                    Id = 2, Name = "Product2", Description = "This is the second product"
                }
            };
            var db = new InMemoryDatabase();

            db.Insert(products);

            using (var connection = db.OpenConnection())
            {
                var unitOfWork = new UnitOfWork.UnitOfWork(connection);
                ProductAsyncRepository productAsyncRepository = new ProductAsyncRepository(unitOfWork);
                var product = new Product {
                    Id = 1, Name = "Product1 Updated", Description = "This is the first updated product"
                };

                // Act
                await productAsyncRepository.UpdateAsync(product);

                // Assert
                var allProducts = db.GetAll <Product>();
                Assert.AreEqual(2, allProducts.Count());

                var firstProduct = allProducts.ToList()[0];
                Assert.IsNotNull(firstProduct);

                Assert.AreEqual(1, firstProduct.Id);
                Assert.AreEqual("Product1 Updated", firstProduct.Name);
                Assert.AreEqual("This is the first updated product", firstProduct.Description);
            }
        }
コード例 #11
0
        public async Task SaveProduct_When_NewProductInserted()
        {
            // Arrange
            var products = new List <Product>
            {
                new Product {
                    Id = 1, Name = "Product1", Description = "This is the first product"
                },
                new Product {
                    Id = 2, Name = "Product2", Description = "This is the second product"
                }
            };
            var db = new InMemoryDatabase();

            db.Insert(products);

            using (var connection = db.OpenConnection())
            {
                var unitOfWork = new UnitOfWork.UnitOfWork(connection);
                ProductAsyncRepository productAsyncRepository = new ProductAsyncRepository(unitOfWork);
                var product = new Product {
                    Id = 3, Name = "Product3", Description = "This is the third product"
                };

                // Act
                await productAsyncRepository.SaveAsync(product);

                // Assert
                var allProducts = db.GetAll <Product>();
                Assert.AreEqual(3, allProducts.Count());

                var thirdProduct = allProducts.ToList()[2];
                Assert.IsNotNull(thirdProduct);

                Assert.AreEqual(3, thirdProduct.Id);
                Assert.AreEqual("Product3", thirdProduct.Name);
                Assert.AreEqual("This is the third product", thirdProduct.Description);
            }
        }