Exemple #1
0
        public void ViewmodelToEntity_ReturnValue_MatchesExpectedState()
        {
            // we're going to run basically the same assertions against the two different
            // overloads, so I'm just going to put it in a lambda
            Action <CustomerViewModel, Customer> doAssertions = (CustomerViewModel vm, Customer e) =>
            {
                Assert.That(vm.Id, Is.EqualTo(e.Id));
                Assert.That(vm.Name, Is.EqualTo(e.Name));
                Assert.That(vm.StreetAddress, Is.EqualTo(e.StreetAddress));

                // If the viewmodel has the 'BillingMatchesStreetAddress' flag,
                // billing+street address should have value equality
                if (vm.BillingMatchesStreetAddress)
                {
                    Assert.That(e.StreetAddress, Is.EqualTo(e.BillingAddress));
                }
                else
                {
                    Assert.That(vm.BillingAddress, Is.EqualTo(e.BillingAddress));
                }

                Assert.That(vm.OfficePhone1, Is.EqualTo(e.OfficePhone1));
                Assert.That(vm.OfficePhone2, Is.EqualTo(e.OfficePhone2));
                Assert.That(vm.OfficeFax, Is.EqualTo(e.OfficeFax));
                Assert.That(vm.Email, Is.EqualTo(e.Email));
                Assert.That(vm.Notes, Is.EqualTo(e.Notes));
                Assert.That(vm.PrimaryContact, Is.EqualTo(e.PrimaryContact));
            };

            converter.ViewmodelToEntity(fakeViewModel, ref fakeEntity);
            doAssertions(fakeViewModel, fakeEntity);

            converter.ViewmodelToEntity(fakeViewModel, ref fakeEntity);
            doAssertions(fakeViewModel, fakeEntity);
        }