public void TestShouldUpdateProduct()
        {
            // Arrange
            var options = SetDbContextOptions();

            SeedDatabase(options);

            using (var context = new ExampleContext(options))
            {
                var sut = CreateEfRepository(context);

                int id = sut.GetProducts("No2").Single().Id;

                // Act
                sut.UpdateProduct(SampleProducts.CreateProduct(id, "No2", "Updated description."));
            }

            // Assert
            using (var context = new ExampleContext(options))
            {
                var result = context.Products.ToList();

                Assert.Equal(3, result.Count);
                Assert.Equal("Updated description.", result.Single(p => p.Name == "No2").Description);
            }
        }
        public void TestShouldInsertProductWhenThereAreSomeAlready()
        {
            // Arrange
            var options = SetDbContextOptions();

            SeedDatabase(options);

            using (var context = new ExampleContext(options))
            {
                var sut = CreateEfRepository(context);

                // Act
                var result = sut.AddProduct(SampleProducts.CreateProduct());

                // Assert
                Assert.True(result.Id > 0);
                Assert.Equal("FirstProduct", result.Name);
            }

            using (var context = new ExampleContext(options))
            {
                var result = context.Products.ToList();

                Assert.Equal(4, result.Count);
                Assert.Equal("This is the first product.", result.Single(p => p.Name == "FirstProduct").Description);
            }
        }
        public void TestShouldInsertProductWhenThereAreNone()
        {
            // Arrange
            var options = SetDbContextOptions();

            using (var context = new ExampleContext(options))
            {
                var sut = CreateEfRepository(context);

                // Act
                var result = sut.AddProduct(SampleProducts.CreateProduct());

                // Assert
                Assert.True(result.Id > 0);
                Assert.Equal("FirstProduct", result.Name);
            }

            using (var context = new ExampleContext(options))
            {
                var result = context.Products.ToList();

                Assert.Equal(1, result.Count);
                Assert.Equal("FirstProduct", result.Single().Name);
            }
        }
        public void TestShouldUpdateProduct()
        {
            // Arrange
            SeedDatabase(_options);

            using (var context = new ExampleContext(_options))
            {
                var sut = CreateEfRepository(context);

                int id = CreateEfQueries(context).GetProducts("No2").Single().Id;

                // Act
                sut.UpdateProduct(SampleProducts.CreateProduct(id, "No2", "Updated description."));
            }

            // Assert
            using (var context = new ExampleContext(_options))
            {
                var result = CreateEfQueries(context).GetProducts().ToList();

                Assert.AreEqual(3, result.Count);
                Assert.AreEqual("Updated description.", result.Single(p => p.Name == "No2").Description);
                Assert.AreEqual(0, result.Single(p => p.Name == "No2").Persons.Count);
            }
        }
        public void TestShouldInsertProductWhenThereAreNone()
        {
            // Arrange
            var sut = CreateInMemoryRepository();

            // Act
            var result = sut.AddProduct(SampleProducts.CreateProduct());

            // Assert
            Assert.AreEqual(1, result.Id);
            Assert.AreEqual("FirstProduct", result.Name);
        }
        public void TestShouldUpdateProduct()
        {
            // Arrange
            var sut = CreateInMemoryRepository(SampleProducts.CreateProducts());

            // Act
            sut.UpdateProduct(SampleProducts.CreateProduct(2, "Updated name", "Updated description."));

            // Assert
            Assert.AreEqual("Updated name", sut.GetProducts(e => e.Id == 2).Single().Name);
            Assert.AreEqual("Updated description.", sut.GetProducts(e => e.Id == 2).Single().Description);
        }
        public void TestShouldRemovePersonFromProductAndNotFindPersonInProduct()
        {
            _queries.GetProduct(1)
                .Returns(SampleProducts.CreateProduct(1));

            _repository.UpdateProduct(SampleProducts.CreateProduct(1));

            // Arrange
            var sut = CreateProductInteractor();

            // Act & Assert
            Assert.ThrowsException<ArgumentNullException>(() => sut.RemovePersonFromProduct(1, 1, Role.Actor));
        }
Esempio n. 8
0
        public void TestShouldMapUpdate()
        {
            // Arrange
            var sut = CreateProduct();

            // Act
            var result = sut.MapUpdate(SampleProducts.CreateProduct(33, "SecondProduct", "This is the second product."), SampleProducts.CreateProduct(2));

            // Assert
            Assert.AreEqual(2, result.Id);
            Assert.AreEqual("SecondProduct", result.Name);
            Assert.AreEqual("This is the second product.", result.Description);
        }
        public void TestShouldUpdateProductFromId()
        {
            // Arrange
            _repository.UpdateProduct(SampleProducts.CreateProduct(3));
            _queries.GetProduct(3).ReturnsForAnyArgs(SampleProducts.CreateProduct(3));

            var sut = CreateProductInteractor();

            // Act
            var result = sut.UpdateProduct(3, "FirstProduct", "This is the first product.");

            // Assert
            Assert.AreEqual("FirstProduct", result.Name);
        }
        public void TestShouldGetProductFromId()
        {
            // Arrange
            _queries.GetProduct(3)
                .ReturnsForAnyArgs(SampleProducts.CreateProduct(3, "ThirdProduct"));

            var sut = CreateProductInteractor();

            // Act
            var result = sut.GetProduct(3);

            // Assert
            Assert.AreEqual("ThirdProduct", result.Name);
        }
        public void TestShouldCreateProduct()
        {
            // Arrange
            _repository.AddProduct(SampleProducts.CreateProduct())
                .ReturnsForAnyArgs(SampleProducts.CreateProduct(1));

            var sut = CreateProductInteractor();

            // Act
            var result = sut.CreateProduct("FirstProduct", "This is the first product.");

            // Assert
            Assert.AreEqual(1, result.Id);
            Assert.AreEqual("This is the first product.", result.Description);
        }
        public void TestShouldGetProductFromId()
        {
            // Arrange
            _productInteractor.GetProduct(1)
            .Returns(SampleProducts.CreateProduct(1));

            var sut = CreateProductController();

            // Act
            var result = sut.GetProduct(1);

            // Assert
            var okResult = (OkObjectResult)result;
            var value    = (Product)okResult.Value;

            Assert.AreEqual((int)HttpStatusCode.OK, okResult.StatusCode);
            Assert.AreEqual("FirstProduct", value.Name);
        }
        public void TestShouldCreateProduct()
        {
            // Arrange
            _productInteractor.CreateProduct("FirstProduct", "This is the first product.")
            .Returns(SampleProducts.CreateProduct(1));

            var sut = CreateProductController();

            // Act
            var result = sut.CreateProduct(SampleProductDtos.CreateProductCreate());

            // Assert
            var createdResult = (CreatedAtRouteResult)result;
            var value         = (Product)createdResult.Value;

            Assert.AreEqual((int)HttpStatusCode.Created, createdResult.StatusCode);
            Assert.AreEqual("FirstProduct", value.Name);
        }
        public void TestShouldAddPersonToProduct()
        {
            // Arrange
            _queries.GetPerson(1)
                .Returns(SamplePersons.CreatePerson(1));

            _queries.GetProduct(1)
                .Returns(SampleProducts.CreateProduct(1));

            _repository.UpdateProduct(SampleProducts.CreateProduct(1));

            var sut = CreateProductInteractor();

            // Act
            sut.AddPersonToProduct(1, 1, Role.Actor);

            // Assert
            Assert.IsTrue(true);
        }
Esempio n. 15
0
        public void TestShouldWriteProductsToFile()
        {
            // Arrange
            _dataFile.Value.Returns(new Datafile {
                FileName = ProductsFileName
            });

            var sut = CreateFileHandler();

            var products = sut.Read();

            products.Add(SampleProducts.CreateProduct(3, "ThirdProduct", "This is the third product."));

            // Act
            sut.Write(products);

            // Assert
            var result = sut.Read();

            Assert.AreEqual(3, result.Count);
            Assert.AreEqual("SecondProduct", result.Single(r => r.Id == 2).Name);
            Assert.AreEqual("ThirdProduct", result.Single(r => r.Id == 3).Name);
        }