Example #1
0
        public void VerifyProductRepositoryUpdateMethodIsInvoced_WhenValidParametersAreProvided()
        {
            // Arrange
            var tableRepository   = new Mock <IEfRepository <Table> >();
            var productRepository = new Mock <IEfRepository <Product> >();
            var saveContext       = new Mock <ISaveContext>();

            var table = new Table()
            {
                Id       = Guid.NewGuid(),
                Number   = 1,
                Products = new List <Product>()
            };

            var product = new Product()
            {
                Id           = Guid.NewGuid(),
                Name         = "Coca cola",
                Price        = 5,
                Quantity     = 500,
                QuantityType = QuantityType.Milliliters,
                Tables       = new List <Table>()
            };

            ITableService tableService = new TableService(
                tableRepository.Object,
                productRepository.Object,
                saveContext.Object);

            // Act
            tableService.AddProductToTable(product, table);

            // Assert
            productRepository.Verify(x => x.Update(product), Times.Once());
        }
Example #2
0
        public void Throw_WhenInvalidTableAreProvided()
        {
            // Arrange
            var tableRepository   = new Mock <IEfRepository <Table> >();
            var productRepository = new Mock <IEfRepository <Product> >();
            var saveContext       = new Mock <ISaveContext>();

            var product = new Product()
            {
                Id           = Guid.NewGuid(),
                Name         = "Coca cola",
                Price        = 5,
                Quantity     = 500,
                QuantityType = QuantityType.Milliliters,
                Tables       = new List <Table>()
            };

            ITableService tableService = new TableService(
                tableRepository.Object,
                productRepository.Object,
                saveContext.Object);

            // Act & Assert
            Assert.Throws <NullReferenceException>(() =>
                                                   tableService.AddProductToTable(product, null));
        }
Example #3
0
        public void Throw_WhenInvalidProductAreProvided()
        {
            // Arrange
            var tableRepository   = new Mock <IEfRepository <Table> >();
            var productRepository = new Mock <IEfRepository <Product> >();
            var saveContext       = new Mock <ISaveContext>();

            var table = new Table()
            {
                Id       = Guid.NewGuid(),
                Number   = 1,
                Products = new List <Product>()
            };

            ITableService tableService = new TableService(
                tableRepository.Object,
                productRepository.Object,
                saveContext.Object);

            // Act & Assert
            Assert.Throws <NullReferenceException>(() =>
                                                   tableService.AddProductToTable(null, table));
        }
Example #4
0
        public void SuccessfullyAddProductToTable_WhenValidParameterAreProvided()
        {
            // Arrange
            var tableRepository   = new Mock <IEfRepository <Table> >();
            var productRepository = new Mock <IEfRepository <Product> >();
            var saveContext       = new Mock <ISaveContext>();

            var table = new Table()
            {
                Id       = Guid.NewGuid(),
                Number   = 1,
                Products = new List <Product>()
            };

            var product = new Product()
            {
                Id           = Guid.NewGuid(),
                Name         = "Coca cola",
                Price        = 5,
                Quantity     = 500,
                QuantityType = QuantityType.Milliliters,
                Tables       = new List <Table>()
            };

            ITableService tableService = new TableService(
                tableRepository.Object,
                productRepository.Object,
                saveContext.Object);

            // Act
            tableService.AddProductToTable(product, table);

            // Assert
            Assert.IsTrue(product.Tables.Contains(table));
            Assert.IsTrue(table.Products.Contains(product));
        }