Exemple #1
0
        public void CreateConverter_AnchestorUnits_CanCreateConverters()
        {
            // Arrange
            var        mockConverter = new Mock <IValueConverter>();
            UnitSystem system        = new UnitSystem();
            IDimension dimension     = CreateStubDimension("M");
            IUnit      baseunit      = CreateStubUnit("base", dimension);
            IUnit      scaledunit    = CreateStubUnit("scaled", dimension);

            system.AddDimension(dimension);
            system.AddBaseUnit(baseunit);
            system.AddScaledUnit(baseunit, scaledunit, mockConverter.Object);

            // Act
            IValueConverter toScaledConverter   = system.CreateConverter(baseunit, scaledunit);
            IValueConverter fromScaledConverter = system.CreateConverter(scaledunit, baseunit);

            // Assert
            Assert.NotNull(toScaledConverter);
            Assert.NotNull(fromScaledConverter);
        }
Exemple #2
0
        public void CreateConverter_IndirectlyRelatedUnits_CanCreateConverters()
        {
            // Arrange
            UnitSystem system      = new UnitSystem();
            IDimension dimension   = CreateStubDimension("M");
            IUnit      baseunit    = CreateStubUnit("base", dimension);
            IUnit      scaledunit1 = CreateStubUnit("scaled1", dimension);
            IUnit      scaledunit2 = CreateStubUnit("scaled2", dimension);

            system.AddDimension(dimension);
            system.AddBaseUnit(baseunit);
            // Conversion between scaleduni1 and scaledunit2 through baseunit
            system.AddScaledUnit(baseunit, scaledunit1, CreateStubConverter(baseunit, scaledunit1));
            system.AddScaledUnit(baseunit, scaledunit2, CreateStubConverter(baseunit, scaledunit2));

            // Act
            IValueConverter converter = system.CreateConverter(scaledunit1, scaledunit2);

            // Assert
            Assert.NotNull(converter);
        }