public void InventoryController_TakeOutByLabel_ReturnsInventoryItem_WhenAddedInventoryExists(int addYears)
        {
            // Arrange
            var itemLabel = "Newest inventory " + Guid.NewGuid();
            var expirationDate = DateTime.Now.AddYears(addYears);
            var inventoryItem = new Inventory { Label = itemLabel, ExpirationDate = expirationDate };

            // Act
            _inventoryController.Add(inventoryItem);
            var result = _inventoryController.TakeOutByLabel(itemLabel);

            // Assert
            Assert.That(result.Label, Is.EqualTo(itemLabel));
        }
示例#2
0
        public void InventoryService_NoNotificationSending_WhenItemDoesNotExist()
        {
            // Arrange
            var itemLabel = "Newest inventory " + Guid.NewGuid();
            var expirationDate = DateTime.Now.AddYears(+1);
            var inventoryItem = new Inventory { Label = itemLabel, ExpirationDate = expirationDate };
            //_inventoryRepository.GetByLabel(Arg.Any<string>()).Returns(inventoryItem);

            // Act
            _inventoryService.TakeOutByLabel(itemLabel);

            // Assert
            _notificationService.DidNotReceiveWithAnyArgs().Send(Arg.Any<Notification>());
        }
示例#3
0
        public void InventoryService_NotificationSent_WhenItemIsNotExpiredAndTakenOut()
        {
            // Arrange
            var itemLabel = "Newest inventory " + Guid.NewGuid();
            var expirationDate = DateTime.Now.AddYears(+1);
            var inventoryItem = new Inventory { Label = itemLabel, ExpirationDate = expirationDate };
            _inventoryRepository.GetByLabel(Arg.Any<string>()).Returns(inventoryItem);

            // Act
            _inventoryService.TakeOutByLabel(itemLabel);

            // Assert
            _notificationService.Received(1).Send(Arg.Is<Notification>(x => x.Code == NotificationCode.ItemHasBeenTakenOut));
        }
        public void InventoryRepository_SavedItemContainsLabelAndExpirationDate()
        {
            // Arrange
            var itemLabel = "Newest inventory " + Guid.NewGuid();
            var expirationDate = DateTime.Now;
            var inventoryItem = new Inventory { Label = itemLabel, ExpirationDate = expirationDate };

            // Act
            _inventoryRepository.Save(inventoryItem);
            var inventoryItembyLabel = _inventoryRepository.GetByLabel(itemLabel);

            // Assert
            Assert.That(inventoryItembyLabel.Label, Is.EqualTo(itemLabel));
            Assert.That(inventoryItembyLabel.ExpirationDate, Is.EqualTo(expirationDate));
        }
        public void InventoryRepository_DeletesItem()
        {
            // Arrange
            var itemLabel = "Newest inventory " + Guid.NewGuid();
            var expirationDate = DateTime.Now;
            var inventoryItem = new Inventory { Label = itemLabel, ExpirationDate = expirationDate };

            // Act
            _inventoryRepository.Save(inventoryItem);
            _inventoryRepository.Delete(inventoryItem);
            var inventoryItembyLabel = _inventoryRepository.GetByLabel(itemLabel);

            // Assert
            Assert.That(inventoryItembyLabel, Is.Null);
        }
        public void InventoryController_TakeOutByLabel_ReturnsNothing_WhenAddedInventoryWasTakenBefore()
        {
            // Arrange
            var itemLabel = "Newest inventory " + Guid.NewGuid();
            var expirationDate = DateTime.Now;
            var inventoryItem = new Inventory { Label = itemLabel, ExpirationDate = expirationDate };

            // Act
            _inventoryController.Add(inventoryItem);
            _inventoryController.TakeOutByLabel(itemLabel);
            var result = _inventoryController.TakeOutByLabel(itemLabel);

            // Assert
            Assert.That(result, Is.Null);
        }
示例#7
0
        public void InventoryService_ItemIsDeletedAfterTakingIt()
        {
            // Arrange
            var itemLabel = "Newest inventory " + Guid.NewGuid();
            var expirationDate = DateTime.Now;
            var inventoryItem = new Inventory { Label = itemLabel, ExpirationDate = expirationDate };
            _inventoryRepository.GetByLabel(Arg.Any<string>()).Returns(inventoryItem);

            // Act
            _inventoryService.TakeOutByLabel(itemLabel);

            // Assert
            _inventoryRepository.Received(1).GetByLabel(Arg.Is(itemLabel));
            _inventoryRepository.Received(1).Delete(Arg.Any<Inventory>());
        }
示例#8
0
 public void Save(Inventory item)
 {
     _inventoryRepository.Save(item);
 }
示例#9
0
 public HttpResponseMessage Add(Inventory item)
 {
     _inventoryService.Save(item);
     return Request.CreateResponse(HttpStatusCode.OK);
 }
示例#10
0
 public void Save(Inventory item)
 {
     InventoryItemList.Add(item);
 }
示例#11
0
 public void Delete(Inventory item)
 {
     InventoryItemList.Remove(item);
 }