コード例 #1
0
        public void ThrowArgumentNullException_WhenPassedStatusIsInvalid()
        {
            // Arrange
            var contextMock = new Mock <ITravelGuideContext>();
            var factoryMock = new Mock <IStoreItemFactory>();

            var id      = Guid.NewGuid();
            var service = new StoreServiceMock(contextMock.Object, factoryMock.Object);

            // Act & Assert
            Assert.Throws <ArgumentException>(() => service.ChangeStatus(id, null));
        }
コード例 #2
0
        public void ThrowInvalidOperationException_WhenNoSuchItemIsFound()
        {
            // Arrange
            var contextMock = new Mock <ITravelGuideContext>();
            var factoryMock = new Mock <IStoreItemFactory>();

            var id   = Guid.NewGuid();
            var item = new StoreItem();

            item.InStock = true;
            var initialValue = item.InStock;

            contextMock.Setup(x => x.StoreItems.Find(It.IsAny <Guid>())).Returns((StoreItem)null);
            var service = new StoreServiceMock(contextMock.Object, factoryMock.Object);

            // Act
            Assert.Throws <InvalidOperationException>(() => service.ChangeStatus(id, "false"));
        }
コード例 #3
0
        public void AlterPassedInstance_WhenPassedStatusIsValid()
        {
            // Arrange
            var contextMock = new Mock <ITravelGuideContext>();
            var factoryMock = new Mock <IStoreItemFactory>();

            var id   = Guid.NewGuid();
            var item = new StoreItem();

            item.InStock = true;
            var initialValue = item.InStock;

            contextMock.Setup(x => x.StoreItems.Find(It.IsAny <Guid>())).Returns(item);
            var service = new StoreServiceMock(contextMock.Object, factoryMock.Object);

            // Act
            service.ChangeStatus(id, "false");

            // Assert
            Assert.IsTrue(initialValue);
            Assert.IsFalse(item.InStock);
        }