예제 #1
0
        public void CreateFrom_IUnitSystem_AccessesDimensionsAndUnits()
        {
            // Arrange
            const int dimensions        = 3;
            const int unitsperdimension = 3;

            IDimension[] dimensionArray = new []
            {
                CreateStubDimension(),
                CreateStubDimension(),
                CreateStubDimension()
            };

            var mockSystem = new Mock <IUnitSystem>();

            mockSystem.Setup(x => x.Dimensions)
            .Returns(dimensionArray);
            mockSystem.Setup(x => x.GetBaseUnit(It.IsAny <IDimension>()))
            .Returns <IDimension>(x => CreateStubUnit("", x));
            mockSystem.Setup(x => x.GetSupportedUnits(It.IsAny <IDimension>()))
            .Returns <IDimension>(x => Enumerable.Repeat(CreateStubUnit("", x), unitsperdimension));

            // Act
            UnitSystem system = UnitSystem.CreateFrom(mockSystem.Object);

            // Assert
            Assert.NotNull(system);
            mockSystem.Verify(x => x.Dimensions, Times.AtLeastOnce());
            mockSystem.Verify(x => x.GetBaseUnit(It.IsAny <IDimension>()), Times.AtLeast(dimensions));
            mockSystem.Verify(x => x.GetSupportedUnits(It.IsAny <IDimension>()), Times.AtLeast(dimensions));
        }