public void AssignFactoryValueProperly_WhenInputParamsAreValid() { // Arrange var contextMock = new Mock <ITravelGuideContext>(); var factoryMock = new Mock <IStoreItemFactory>(); // Act var service = new StoreServiceMock(contextMock.Object, factoryMock.Object); // Assert Assert.AreSame(factoryMock.Object, service.Factory); }
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)); }
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")); }
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); }