Ejemplo n.º 1
0
        public void AddOperationTemplated_ExistingType_ThrowsArgumentException()
        {
            // Arrange
            OperationStore store = new OperationStore();
            Func <QuantityBase, QuantityBase, QuantityBase> operation = CreateMockOperation().Object.Operation;

            store.AddOperation <Quantity <float>, Quantity <double> >(operation);
            // Act/assert
            Assert.Throws <ArgumentException>(() => store.AddOperation <Quantity <float>, Quantity <double> >(operation));
        }
Ejemplo n.º 2
0
        public void AddOperation_TypeDoesNotInheritdQuantityBase_ThrowsInvalidCastException()
        {
            // Arrange
            OperationStore store = new OperationStore();
            Func <QuantityBase, QuantityBase, QuantityBase> operation = CreateMockOperation().Object.Operation;

            // Act/assert
            Assert.Throws <InvalidCastException>(() => store.AddOperation(typeof(string), typeof(int), operation));
        }
Ejemplo n.º 3
0
        public void AddOperation_ValidTypes_DoesNotThrow()
        {
            // Arrange
            OperationStore store = new OperationStore();
            Func <QuantityBase, QuantityBase, QuantityBase> operation = CreateMockOperation().Object.Operation;

            // Act/assert
            Assert.DoesNotThrow(() => store.AddOperation(typeof(Quantity <float>), typeof(Quantity <float>), operation));
        }
Ejemplo n.º 4
0
        public void PerformOperation_CommutativeTypes_ThrowsInvalidOperationException()
        {
            // Arrange
            OperationStore store         = new OperationStore();
            var            mockOperation = CreateMockOperation();

            store.AddOperation <int, float>(mockOperation.Object.Operation);
            // Act/Assert
            Assert.Throws <InvalidOperationException>(() => store.PerformOperation(CreateStubQuantity <float>(),
                                                                                   CreateStubQuantity <int>()));
        }
Ejemplo n.º 5
0
        public void PerformOperation_RegisteredTypes_InvokesOperation()
        {
            // Arrange
            OperationStore store         = new OperationStore();
            var            mockOperation = CreateMockOperation();

            store.AddOperation <int, int>(mockOperation.Object.Operation);
            // Act
            store.PerformOperation(CreateStubQuantity <int>(), CreateStubQuantity <int>());
            // Assert
            mockOperation.Verify(x => x.Operation(It.IsAny <QuantityBase>(), It.IsAny <QuantityBase>()), Times.Once());
        }