public void Divide_UnregisteredType_ThrowsInvalidOperationException() { // Arrange IUnit unit = new Mock <IUnit>().Object; ArithmeticsStore store = CreateStore(); // Act/assert Assert.Throws <InvalidOperationException>(() => store.Divide(new Quantity <float>(1.0f, unit), new Quantity <float>(1.0f, unit))); }
public void Divide_RegisteredType_InvokesOperation() { // Arrange var mockDelegate = new Mock <IOperationFunction>(); IUnit unit = new Mock <IUnit>().Object; ArithmeticsStore store = CreateStore(); store.RegisterDivideOperation <float, float>(mockDelegate.Object.Operation); // Act/assert Assert.DoesNotThrow(() => store.Divide(new Quantity <float>(1.0f, unit), new Quantity <float>(1.0f, unit))); mockDelegate.Verify(x => x.Operation(It.IsAny <QuantityBase>(), It.IsAny <QuantityBase>()), Times.Once()); }
public void Divide_RegisteredTypeButNotMatchingDimension_InvokesOperation() { // Arrange var mockDelegate = new Mock <IOperationFunction>(); var stubUnit1 = new Mock <IUnit>(); stubUnit1.Setup(x => x.Dimension).Returns(new Mock <IDimension>().Object); var stubUnit2 = new Mock <IUnit>(); stubUnit2.Setup(x => x.Dimension).Returns(new Mock <IDimension>().Object); ArithmeticsStore store = CreateStore(); store.RegisterDivideOperation <float, float>(mockDelegate.Object.Operation); // Act/assert Assert.DoesNotThrow(() => store.Divide(new Quantity <float>(1.0f, stubUnit1.Object), new Quantity <float>(1.0f, stubUnit2.Object))); mockDelegate.Verify(x => x.Operation(It.IsAny <QuantityBase>(), It.IsAny <QuantityBase>()), Times.Once()); }