Example #1
0
        public IActionResult EditIncludedAddress(EditAddressViewModel input)
        {
            if (!ModelState.IsValid)
            {
                var modelReceiver = _receiversService.GetReceiverByAddressId(input.Id);
                var modelAddress  = modelReceiver.DeliveryAddresses.FirstOrDefault(x => x.Id == input.Id);
                return(this.View(modelAddress));
            }
            var address  = _receiversService.EditIncludedAddress(input.Id, input.Town, input.Street);
            var receiver = _receiversService.GetReceiverByAddressId(input.Id);

            return(this.Redirect($"/Receivers/Edit?id={receiver.Id}"));
        }
Example #2
0
        public void EditIncludedAddress_works_Properly()
        {
            string errorMessagePrefix = "ReceiverService EditIncludedAddress() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.receiverService = new ReceiverService(context);

            var address = new DeliveryAddress()
            {
                Town   = "Town1",
                Street = "Street1",
            };

            context.DeliveryAddresses.Add(address);
            context.SaveChanges();

            var result = receiverService.EditIncludedAddress(address.Id, "Town2", "Street2");

            Assert.True(context.DeliveryAddresses.First().Town == "Town2");
            Assert.True(context.DeliveryAddresses.First().Street == "Street2");
        }