Exemplo n.º 1
0
        public void Add_UnregisteredType_ThrowsInvalidOperationException()
        {
            // Arrange
            IUnit            unit  = new Mock <IUnit>().Object;
            ArithmeticsStore store = CreateStore();

            // Act/assert
            Assert.Throws <InvalidOperationException>(() => store.Add(new Quantity <float>(0.0f, unit), new Quantity <float>(0.0f, unit)));
        }
Exemplo n.º 2
0
        public void Add_RegisteredsTypeButNotMatchingUnit_ThrowsArgumentException()
        {
            // Arrange
            var              mockDelegate = new Mock <IOperationFunction>();
            IUnit            unit1        = new Mock <IUnit>().Object;
            IUnit            unit2        = new Mock <IUnit>().Object;
            ArithmeticsStore store        = CreateStore();

            store.RegisterAddOperation <float>(mockDelegate.Object.Operation);
            // Act/assert
            Assert.Throws <ArgumentException>(() => store.Add(new Quantity <float>(0.0f, unit1), new Quantity <float>(0.0f, unit2)));
        }
Exemplo n.º 3
0
        public void Add_RegisteredType_InvokesOperation()
        {
            // Arrange
            var              mockDelegate = new Mock <IOperationFunction>();
            IUnit            unit         = new Mock <IUnit>().Object;
            ArithmeticsStore store        = CreateStore();

            store.RegisterAddOperation <float>(mockDelegate.Object.Operation);
            // Act/assert
            Assert.DoesNotThrow(() => store.Add(new Quantity <float>(0.0f, unit), new Quantity <float>(0.0f, unit)));
            mockDelegate.Verify(x => x.Operation(It.IsAny <QuantityBase>(), It.IsAny <QuantityBase>()), Times.Once());
        }