Пример #1
0
        public void ShouldApplyMultipleConfiguredComplexTypeSourceValues()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <CtorTester <int> >()
                .ToANew <CtorTester <int> >()
                .If(ctx => ctx.Source.Value < 5)
                .Map(new Address {
                    Line1 = "< 5"
                })
                .ToCtor <Address>()
                .But
                .If(ctx => ctx.Source.Value < 10)
                .Map(new Address {
                    Line1 = "< 10"
                })
                .ToCtor <Address>()
                .But
                .If(ctx => ctx.Source.Value < 15)
                .Map(new Address {
                    Line1 = "< 15"
                })
                .ToCtor <Address>();

                var lessThanFiveSource = new CtorTester <int>(3);
                var lessThanFiveResult = lessThanFiveSource.DeepCloneUsing(mapper);

                lessThanFiveResult.Value.ShouldBe(3);
                lessThanFiveResult.Address.ShouldNotBeNull().Line1.ShouldBe("< 5");

                var lessThanTenSource = new CtorTester <int>(6);
                var lessThanTenResult = lessThanTenSource.DeepCloneUsing(mapper);

                lessThanTenResult.Value.ShouldBe(6);
                lessThanTenResult.Address.ShouldNotBeNull().Line1.ShouldBe("< 10");

                var lessThanFifteenSource = new CtorTester <int>(14);
                var lessThanFifteenResult = lessThanFifteenSource.DeepCloneUsing(mapper);

                lessThanFifteenResult.Value.ShouldBe(14);
                lessThanFifteenResult.Address.ShouldNotBeNull().Line1.ShouldBe("< 15");

                var addressSource = new CtorTester <int>(123, new Address {
                    Line1 = "One!", Line2 = "Two!"
                });
                var addressResult = addressSource.DeepCloneUsing(mapper);

                addressResult.Value.ShouldBe(123);
                addressResult.Address.ShouldNotBeNull().ShouldNotBeSameAs(addressSource.Address);
                addressResult.Address.Line1.ShouldBe("One!");
                addressResult.Address.Line2.ShouldBe("Two!");

                var noAddressSource = new CtorTester <int>(789);
                var noAddressResult = noAddressSource.DeepCloneUsing(mapper);

                noAddressResult.Value.ShouldBe(789);
                noAddressResult.Address.ShouldBeNull();
            }
        }
        public void ShouldConditionallyUseConstructorsWhereArgumentsAreNull()
        {
            var noAddressSource = new CtorTester("Test 1");
            var noAddressResult = noAddressSource.DeepClone();

            noAddressResult.Value.ShouldBe("Test 1");
            noAddressResult.Address.ShouldBeNull();

            var addressSource = new CtorTester("Test 2", new Address {
                Line1 = "Line 1!"
            });
            var addressResult = addressSource.DeepClone();

            addressResult.Value.ShouldBe("Test 2");
            addressResult.Address.ShouldNotBeNull();
            addressResult.Address.ShouldNotBeSameAs(addressSource.Address);
            addressResult.Address.Line1.ShouldBe("Line 1!");
        }
        public void TestCtorArgumentsChecking()
        {
            var ctorTester =
            new CtorTester<DeployNtServiceDeploymentTask>(
              new object[]
            {
              _environmentInfoRepository.Object,
              _artifactsRepository.Object,
              _ntServiceManager.Object,
              _passwordCollector.Object,
              _failoverClusterManager.Object,
              _ntServiceProjectInfo,
              _ProjectName,
              _BuildId,
              _EnvironmentName,
            }
              );

              ctorTester.TestAll();
        }
        public void TestCtorArgumentsChecking()
        {
            var ctorTester =
            new CtorTester<DeployNtServiceDeploymentTask>(
              new object[]
              {
            _projectInfoRepository.Object,
            _environmentInfoRepository.Object,
            _artifactsRepository.Object,
            _ntServiceManager.Object,
            _passwordCollector.Object,
            _failoverClusterManager.Object,
            _directoryAdapter.Object,
            _fileAdapter.Object,
            _zipFileAdapter.Object,
              }
              );

              ctorTester.TestAll();
        }