Пример #1
0
        public void createItem_happyPath()
        {
            Item item = ItemTestBuilder.AnItem().Build();

            Item createdItem = _itemService.CreateItem(item);

            Assert.NotNull(createdItem);
        }
        public void createItem_happyPath()
        {
            Item item = ItemTestBuilder.AnItem().Build();

            _itemRepository.Save(item).Returns(item);
            Item createdItem = _itemService.CreateItem(item);

            Assert.NotNull(createdItem);
        }
        public void updateItem_happyPath()
        {
            Item item = ItemTestBuilder.AnItem().WithId(Guid.NewGuid()).Build();

            _itemRepository.Update(item).Returns(item);
            Item updatedItem = _itemService.UpdateItem(item);

            Assert.NotNull(updatedItem);
        }
        public void GetItem()
        {
            Item createdItem = _itemService.CreateItem(ItemTestBuilder.AnItem().Build());

            Item itemFromDb = _itemService.GetItem(createdItem.Id);

            Assert.NotNull(itemFromDb);
            Assert.Equal(JsonConvert.SerializeObject(createdItem), JsonConvert.SerializeObject(itemFromDb));
        }
        public void updateItem_givenItemThatIsNotValidForUpdating_thenThrowException()
        {
            Item item = ItemTestBuilder.AnItem()
                        .WithAmountOfStock(0)
                        .Build();

            Exception ex = Assert.Throws <InvalidOperationException>(() => _itemService.UpdateItem(item));

            Assert.Contains("Invalid Item provided for updating", ex.Message);
        }
        public void createItem_givenItemThatIsNotValidForCreation_thenThrowException()
        {
            Item item = ItemTestBuilder.AnItem()
                        .WithName(string.Empty)
                        .Build();

            Exception ex = Assert.Throws <InvalidOperationException>(() => _itemService.CreateItem(item));

            Assert.Contains("Invalid Item provided for creation", ex.Message);
        }
        public void GetAllItems()
        {
            Item createdItem1 = _itemService.CreateItem(ItemTestBuilder.AnItem().Build());
            Item createdItem2 = _itemService.CreateItem(ItemTestBuilder.AnItem().Build());

            var allItems = _itemService.GetAllItems().ToList();

            Assert.Contains(JsonConvert.SerializeObject(createdItem1), JsonConvert.SerializeObject(allItems));
            Assert.Contains(JsonConvert.SerializeObject(createdItem2), JsonConvert.SerializeObject(allItems));
        }
Пример #8
0
        public void updateItem_happyPath()
        {
            Item item = ItemTestBuilder.AnItem().WithId(Guid.NewGuid()).Build();

            item = _itemService.CreateItem(item);

            item.Description = "UpdatedDesc";
            Item updatedItem = _itemService.UpdateItem(item);

            Assert.NotNull(updatedItem);
            Assert.Equal("UpdatedDesc", updatedItem.Description);
        }
        public void CreateItem()
        {
            Item createdItem = _itemService.CreateItem(ItemTestBuilder.AnItem()
                                                       .WithName("The Martian")
                                                       .WithDescription("A cool book written by a software engineer")
                                                       .WithAmountOfStock(239)
                                                       .WithPrice(Price.Create(new decimal(10.90)))
                                                       .Build());

            Assert.NotNull(createdItem);
            Assert.NotEqual(Guid.Empty, createdItem.Id);
            Assert.Equal("The Martian", createdItem.Name);
            Assert.Equal("A cool book written by a software engineer", createdItem.Description);
            Assert.Equal(239, createdItem.AmountOfStock);
            Assert.Equal(new decimal(10.90), createdItem.Price.Amount);
        }
 public void isValidForUpdating_happyPath()
 {
     Assert.True(new ItemValidator().IsValidForUpdating(ItemTestBuilder.AnItem().WithId(Guid.NewGuid()).Build()));
 }
 public void isValidForCreation_happyPath()
 {
     Assert.True(new ItemValidator().IsValidForCreation(ItemTestBuilder.AnItem().Build()));
 }
 public void isValidForCreation_givenId_thenNotValidForCreation()
 {
     Assert.False(new ItemValidator().IsValidForCreation(ItemTestBuilder.AnItem().WithId(Guid.NewGuid()).Build()));
 }
 public void isValidForCreation_givenEmptyDescription_thenNotValidForCreation()
 {
     Assert.False(new ItemValidator().IsValidForCreation(ItemTestBuilder.AnItem().WithDescription(string.Empty).Build()));
 }
 public void isValidForUpdating_givenNoId_thenNotValidForUpdating()
 {
     Assert.False(new ItemValidator().IsValidForUpdating(ItemTestBuilder.AnItem().Build()));
 }
 public void isValidForCreation_givenNegativeStock_thenNotValidForCreation()
 {
     Assert.False(new ItemValidator().IsValidForCreation(ItemTestBuilder.AnItem().WithAmountOfStock(-1).Build()));
 }
 public void isValidForCreation_givenNullPrice_thenNotValidForCreation()
 {
     Assert.False(new ItemValidator().IsValidForCreation(ItemTestBuilder.AnItem().WithPrice(null).Build()));
 }
 public void isValidForCreation_givenNegativePrice_thenNotValidForCreation()
 {
     Assert.False(new ItemValidator().IsValidForCreation(ItemTestBuilder.AnItem().WithPrice(Price.Create(new decimal(-1))).Build()));
 }