예제 #1
0
        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));
        }
예제 #4
0
        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));
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
 }