public Domains.Municipalities ConvertToMunicipalities()
        {
            var address = new Domains.Address
            {
                Id       = AddressId,
                Address1 = MunicipalAddress.Address1,
                Address2 = MunicipalAddress.Address2,
                Address3 = MunicipalAddress.Address3,
                City     = MunicipalAddress.City,
                State    = MunicipalAddress.State,
                Zip      = MunicipalAddress.Zip,
                Phone    = MunicipalAddress.Phone,
                Fax      = MunicipalAddress.Fax,
                //Address1 = Address1,
                //Address2 = Address2,
                //Address3 = Address3,
                //City = City,
                //State = State,
                //Zip = Zip,
                //Phone = Phone,
                //Fax = Fax,
                CreationTime         = CreationTime,
                CreatorUserId        = CreatorUserId,
                DeleterUserId        = DeleterUserId,
                DeletionTime         = DeletionTime,
                LastModificationTime = LastModificationTime,
                LastModifierUserId   = LastModifierUserId
            };


            var municipalities = new Domains.Municipalities
            {
                Id                   = Id,
                Name                 = Name,
                IsActive             = IsActive,
                PointOfContact       = PointOfContact,
                Email                = Email,
                AddressId            = AddressId,
                CreatorUserId        = CreatorUserId,
                CreationTime         = CreationTime,
                DeleterUserId        = DeleterUserId,
                DeletionTime         = DeletionTime,
                LastModificationTime = LastModificationTime,
                LastModifierUserId   = LastModifierUserId,
                Address              = address
            };

            return(municipalities);
        }
Exemple #2
0
        public async Task Municipalities_Save_Updated_Items()
        {
            //Arrange
            Client.DefaultRequestHeaders.Add("my-name", "admin");
            Client.DefaultRequestHeaders.Add("my-id", "2");

            //checking for original data
            var addressModel = new AddressViewModel()
            {
                Id = 0, Address1 = "123 Straight Way", City = "Arlington", State = 17, Zip = "76012", Phone = "8175555556"
            };

            var originalData = new Domains.Municipalities();

            UsingDbContext(context =>
            {
                originalData = context.Municipalities.Include(x => x.Address).FirstOrDefault(x => x.Id == 1);
                originalData.ShouldNotBeNull();
                originalData.IsActive.ShouldBe(true);
            });

            var viewModelSave = new MunicipalitiesViewModel(originalData.MapTo <MunicipalitiesDto>());

            // viewModelSave.Phone = "8175555556";
            viewModelSave.IsActive = false;
            var data = JsonConvert.SerializeObject(viewModelSave);

            var url = GetUrl <MunicipalitiesController>(nameof(MunicipalitiesController.SaveMunicipalities),
                                                        new
            {
                viewModelSave.Id,
                viewModelSave.Name,
                viewModelSave.PointOfContact,
                viewModelSave.Email,
                viewModelSave.CreationTime,
                viewModelSave.LastModificationTime,
                viewModelSave.IsActive,
                viewModelSave.AddressId,
                //viewModelSave.Address1,
                //viewModelSave.City,
                //viewModelSave.State,
                //viewModelSave.Zip,
                //viewModelSave.Phone
            });
            var content = new StringContent(data, Encoding.UTF8, "application/x-www-form-urlencoded");
            var message = new HttpRequestMessage
            {
                Content    = content,
                Method     = HttpMethod.Post,
                RequestUri =
                    new Uri("http://localhost" + url)
            };



            //Act


            var response = await PostResponseAsObjectAsync <AjaxResponse>(url, content);

            var count = UsingDbContext(context => { return(context.Municipalities.Count(x => x.IsActive)); });

            var municipalities = UsingDbContext(context =>
            {
                return(context.Municipalities.FirstOrDefault(x => x.Id == 1));
            });


            municipalities.IsActive.ShouldBe(false);
            //Assert
            response.ShouldBeOfType <AjaxResponse>();
            response.Result.ShouldNotBeNull();
            count.ShouldBe(1);
        }