public void ShouldInsertIntoDatabase()
        {
            var testHelper = new TestHelper();

            testHelper.DatabaseDataDeleter(() =>
            {
                var officeDto0 = new OfficeDto()
                {
                    Name        = "Austin",
                    Address     = "Dimensional Place 6300 Bee Cave Road",
                    CountrySlug = "C1",
                    Switchboard = "***REMOVED***",
                    Fax         = "+***REMOVED***",
                    Operating   = 1
                };

                var officeDto1 = new OfficeDto()
                {
                    Name        = "Berlin",
                    Address     = "***REMOVED*** Kurfürstendamm 194, D - 10707 Berlin",
                    CountrySlug = "C2",
                    Switchboard = "***REMOVED***",
                    Fax         = "***REMOVED***",
                    Operating   = 0
                };

                var expectedOfficeId1 = testHelper.InsertOfficeDto(officeDto0);

                var userWrapper = testHelper.GetUserWrapper();
                userWrapper.MakeUserPartOfGroup(userWrapper.GroupNameConstants.AdminGroup);

                var controller = testHelper.CreateController();

                var country1      = testHelper.GetCountryRepository().GetCountryBySlug(officeDto1.CountrySlug);
                var locationModel = new WebOfficeLocation(officeDto1, country1);

                locationModel.HasChanged = "True";

                var locationOffice = new OfficeModel()
                {
                    Offices = new []
                    {
                        locationModel
                    },
                };

                var actionResult = controller.Save(locationOffice);

                //****************************

                var officeLocationRepository = testHelper.GetOfficeLocationRepository();
                var offices = officeLocationRepository.GetAll();

                offices.Length.Should().Be(2);

                offices[0].OfficeId.Should().Be(expectedOfficeId1);
                offices[0].Name.Should().Be("Austin");
                offices[0].Address.Should().Be("Dimensional Place 6300 Bee Cave Road");

                offices[0].Country.Slug.Should().Be("C1");
                offices[0].Country.Name.Should().Be("Country 1");

                offices[0].Switchboard.Should().Be("***REMOVED***");
                offices[0].Fax.Should().Be("+***REMOVED***");
                offices[0].Operating.Should().Be("Active");


                offices[1].OfficeId.Should().BeGreaterThan(0);
                offices[1].Name.Should().Be("Berlin");
                offices[1].Address.Should().Be("***REMOVED*** Kurfürstendamm 194, D - 10707 Berlin");

                offices[1].Country.Slug.Should().Be("C2");
                offices[1].Country.Name.Should().Be("Country 2");

                offices[1].Switchboard.Should().Be("***REMOVED***");
                offices[1].Fax.Should().Be("***REMOVED***");
                offices[1].Operating.Should().Be("Closed");

                //****************************

                var messages = testHelper.GetEmailClient().GetSentMessage();

                messages.Count.Should().Be(1);

                var message = messages.First();

                var expectedSubject = OfficeLocationFacadeHelper.GenerateInsertEmailSubject(
                    locationModel);

                var expectedBody = OfficeLocationFacadeHelper.GenerateInsertEmailBody(
                    locationModel);

                message.Body.Should().Be(expectedBody);
                message.Subject.Should().Be(expectedSubject);

                message.To.Count.Should().Be(2);
                var toArray = message.To.ToArray();

                toArray[0].Should().Be("*****@*****.**");
                toArray[1].Should().Be("*****@*****.**");

                message.From.Should().Be("*****@*****.**");
            });
        }
        public void ShouldUpdateOfficesWithNewInfo()
        {
            var testHelper = new TestHelper();

            testHelper.DatabaseDataDeleter(() =>
            {
                var officeDto0 = new OfficeDto()
                {
                    Name        = "Austin",
                    Address     = "Dimensional Place 6300 Bee Cave Road",
                    CountrySlug = "C1",
                    Switchboard = "***REMOVED***",
                    Fax         = "+***REMOVED***",
                    Operating   = 1
                };

                var expectedOfficeId = testHelper.InsertOfficeDto(officeDto0);

                var userWrapper = testHelper.GetUserWrapper();
                userWrapper.MakeUserPartOfGroup(userWrapper.GroupNameConstants.AdminGroup);

                var controller = testHelper.CreateController();

                var updatedOfficeDto = SimulateUpdatingOfficeLocation(expectedOfficeId);

                var country1      = testHelper.GetCountryRepository().GetCountryBySlug(updatedOfficeDto.CountrySlug);
                var locationModel = new WebOfficeLocation(updatedOfficeDto, country1);

                locationModel.HasChanged = "True";

                var locationOffice = new OfficeModel()
                {
                    Offices = new[]
                    {
                        locationModel, null, new WebOfficeLocation()
                    },
                };

                var actionResult = controller.Save(locationOffice);


                //************************
                var officeLocationRepository = testHelper.GetOfficeLocationRepository();

                var offices = officeLocationRepository.GetAll();

                offices.Length.Should().Be(1);

                offices[0].OfficeId.Should().Be(expectedOfficeId);
                offices[0].Name.Should().Be("Changed");
                offices[0].Address.Should().Be("Updated");

                offices[0].Country.Name.Should().Be("Country 1");
                offices[0].Country.Slug.Should().Be("C1");

                offices[0].Switchboard.Should().Be("Different value here");
                offices[0].Fax.Should().Be("This had changed");
                offices[0].Operating.Should().Be("Closed");

                //****************************

                var messages = testHelper.GetEmailClient().GetSentMessage();

                messages.Count.Should().Be(1);

                var message = messages.First();

                var originalCountry        = testHelper.GetCountryRepository().GetCountryBySlug(officeDto0.CountrySlug);
                var originalOfficeLocation = new OfficeLocation(officeDto0, originalCountry);

                var expectedSubject = OfficeLocationFacadeHelper.GenerateUpdateEmailSubject(
                    originalOfficeLocation);

                var expectedBody = OfficeLocationFacadeHelper.GenerateUpdateEmailBody(
                    locationModel, originalOfficeLocation);

                message.Body.Should().Be(expectedBody);
                message.Subject.Should().Be(expectedSubject);

                message.To.Count.Should().Be(2);
                var toArray = message.To.ToArray();

                toArray[0].Should().Be("*****@*****.**");
                toArray[1].Should().Be("*****@*****.**");

                message.From.Should().Be("*****@*****.**");
            });
        }