コード例 #1
0
        public void Clone_NonEmptyContainer_ReturnsContainerWithSameUnits()
        {
            // Arrange
            var        mockDelegate = CreateMockDelegate();
            IDimension mass         = CreateStubDimension("M");
            IUnit      g            = CreateStubUnit("g", mass);
            IUnit      kg           = CreateStubUnit("kg", mass);
            IUnit      lbs          = CreateStubUnit("lbs", mass);

            DimensionContainer original = new DimensionContainer(mass, mockDelegate.Object.Create);

            original.SetBaseUnit(g);
            original.AddUnit(g, kg);
            original.AddUnit(g, lbs);

            // Act
            DimensionContainer cloned = (DimensionContainer)original.Clone();

            // Assert
            Assert.AreSame(original.BaseUnit, cloned.BaseUnit);
            CollectionAssert.AreEquivalent(original.Units, cloned.Units);
            Assert.True(cloned.CanConvert(g, kg));
            Assert.True(cloned.CanConvert(g, lbs));
            Assert.True(cloned.CanConvert(kg, lbs));
        }
コード例 #2
0
        public void AddUnit_BaseunitNotRegistred_ThrowsNullReferenceException()
        {
            // Arrange
            var                mockDelegate = CreateMockDelegate();
            IDimension         dimension    = CreateStubDimension("M");
            IUnit              baseunit     = CreateStubUnit("g", dimension);
            IUnit              scaledunit   = CreateStubUnit("kg", dimension);
            DimensionContainer container    = new DimensionContainer(dimension, mockDelegate.Object.Create);

            // Act/Assert
            Assert.Throws <NullReferenceException>(() => container.AddUnit(baseunit, scaledunit));
        }
コード例 #3
0
        public void CreateConverter_UnitToAnchestor_CallsCreateConverterTwice()
        {
            // Arrange
            var        mockDelegate = CreateMockDelegate();
            IDimension mass         = CreateStubDimension("M");
            IUnit      g            = CreateStubUnit("g", mass);
            IUnit      kg           = CreateStubUnit("kg", mass);
            IUnit      lbs          = CreateStubUnit("lbs", mass);

            DimensionContainer container = new DimensionContainer(mass, mockDelegate.Object.Create);

            container.SetBaseUnit(g);
            container.AddUnit(g, kg);
            container.AddUnit(kg, lbs);

            // Act
            IValueConverter converter = container.CreateConverter(kg, lbs);

            // Assert
            mockDelegate.Verify(x => x.Create(It.IsAny <IUnit>(), It.IsAny <IUnit>()), Times.Exactly(1));
            Assert.NotNull(converter);
        }
コード例 #4
0
        public void CreateConverter_UnitsShareParent_CallsCreateConverterTwice()
        {
            // Arrange
            var        mockDelegate = CreateMockDelegate();
            IDimension mass         = CreateStubDimension("M");
            IUnit      g            = CreateStubUnit("g", mass);
            IUnit      kg           = CreateStubUnit("kg", mass);
            IUnit      lbs          = CreateStubUnit("lbs", mass);

            DimensionContainer container = new DimensionContainer(mass, mockDelegate.Object.Create);

            container.SetBaseUnit(g);
            container.AddUnit(g, kg);
            container.AddUnit(g, lbs);

            // Act
            IValueConverter converter = container.CreateConverter(kg, lbs);

            // Assert
            mockDelegate.Verify(x => x.Create(kg, g), Times.Once());
            mockDelegate.Verify(x => x.Create(g, lbs), Times.Once());
            Assert.NotNull(converter);
        }
コード例 #5
0
        public void AddUnit_DimensionMismatch_ThrowsArgumentException()
        {
            // Arrange
            var                mockDelegate = new Mock <ICreateAdjacentValueConverterDelegateFunctor>();
            IDimension         mass         = CreateStubDimension("M");
            IDimension         length       = CreateStubDimension("L");
            IUnit              kg           = CreateStubUnit("kg", mass);
            IUnit              m            = CreateStubUnit("m", length);
            DimensionContainer container    = new DimensionContainer(mass, mockDelegate.Object.Create);

            container.SetBaseUnit(kg);

            // Act/Assert
            Assert.Throws <ArgumentException>(() => container.AddUnit(kg, m));
        }