public void GetAsync_Return_All_Addresses()
        {
            //Arrange
            List <AddressDomainModel> addressesDomainModelsList = new List <AddressDomainModel>();
            AddressDomainModel        addressDomainModel        = new AddressDomainModel
            {
                Id         = 1,
                CityName   = "ImeGrada",
                StreetName = "ImeUlice"
            };

            addressesDomainModelsList.Add(addressDomainModel);
            IEnumerable <AddressDomainModel>         addressDomainModels = addressesDomainModelsList;
            Task <IEnumerable <AddressDomainModel> > responseTask        = Task.FromResult(addressDomainModels);
            int expectedResultCount = 1;
            int expectedStatusCode  = 200;

            _addressService = new Mock <IAddressService>();
            _addressService.Setup(x => x.GetAllAsync()).Returns(responseTask);
            AddressesController addressesController = new AddressesController(_addressService.Object);

            //Act
            var result     = addressesController.GetAllAddresses().ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultList = ((OkObjectResult)result).Value;
            var addressDomainModelResultList = (List <AddressDomainModel>)resultList;

            //Assert
            Assert.IsNotNull(addressDomainModelResultList);
            Assert.AreEqual(expectedResultCount, addressDomainModelResultList.Count);
            Assert.AreEqual(addressDomainModel.Id, addressDomainModelResultList[0].Id);
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode);
        }
        public void GetAddress_ById_Async_Return_Address_OkObjectResult()
        {
            //Arrange
            AddressDomainModel addressDomainModel = new AddressDomainModel
            {
                Id         = 123,
                CityName   = "Zrenjanin",
                StreetName = "Nikole Pasica"
            };

            int expectedStatusCode = 200;
            Task <AddressDomainModel> responseTask = Task.FromResult(addressDomainModel);

            _addressService = new Mock <IAddressService>();
            _addressService.Setup(x => x.GetByIdAsync(It.IsAny <int>())).Returns(responseTask);
            AddressesController addressController = new AddressesController(_addressService.Object);

            //Act
            var result       = addressController.GetAddressById(addressDomainModel.Id).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var objectResult = ((OkObjectResult)result).Value;
            AddressDomainModel addressDomainResult = (AddressDomainModel)objectResult;

            //Assert
            Assert.IsNotNull(objectResult);
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode);
            Assert.AreEqual(addressDomainModel.Id, addressDomainResult.Id);
        }
예제 #3
0
 /// <summary>
 /// Merges a valid USPS address with an address domain model
 /// </summary>
 /// <param name="addressDomain"></param>
 /// <param name="addressValidateResponse"></param>
 /// <returns></returns>
 public static AddressDomainModel ToCleanAddress(this  AddressDomainModel addressDomainModel, AddressXML addressXML)
 {
     addressDomainModel.City       = addressXML.City;
     addressDomainModel.Line1      = addressXML.Address1;
     addressDomainModel.PostalCode = $"{addressXML.Zip5}-{addressXML.Zip4}";
     addressDomainModel.State      = addressXML.State;
     return(addressDomainModel);
 }
 public static AddressEntity ToAddressEntity(this AddressDomainModel addressDomainModel)
 {
     return(new AddressEntity
     {
         City = addressDomainModel.City,
         Country = addressDomainModel.Country,
         Line1 = addressDomainModel.Line1,
         PostalCode = addressDomainModel.PostalCode,
         State = addressDomainModel.State,
         AddressId = Guid.NewGuid()
     });
 }
        public void PostAsync_CreateTheatre_Throw_DbException_Theatre()
        {
            //Arrange
            string expectedMessage    = "Inner exception error message.";
            int    expectedStatusCode = 400;

            CreateTheatreModel createTheatreModel = new CreateTheatreModel
            {
                Name          = "Bioskop12345",
                CityName      = "grad",
                NumberOfSeats = 12,
                SeatRows      = 12,
                AuditName     = "Sala23"
            };

            TheatreDomainModel theatreDomainModel = new TheatreDomainModel
            {
                Id              = 123,
                AddressId       = 1423,
                Name            = createTheatreModel.Name,
                AuditoriumsList = new List <AuditoriumDomainModel>()
            };

            AddressDomainModel addressDomainModel = new AddressDomainModel
            {
                Id         = 123,
                CityName   = "grad123",
                StreetName = "ulica123"
            };

            Task <TheatreDomainModel> responseTask  = Task.FromResult(theatreDomainModel);
            Task <AddressDomainModel> responseTask2 = Task.FromResult(addressDomainModel);
            Exception         exception             = new Exception("Inner exception error message.");
            DbUpdateException dbUpdateException     = new DbUpdateException("Error.", exception);

            _theatreService = new Mock <ITheatreService>();
            _addressService = new Mock <IAddressService>();

            _theatreService.Setup(x => x.Create(It.IsAny <TheatreDomainModel>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Throws(dbUpdateException);
            _addressService.Setup(x => x.GetByCityNameAsync(It.IsAny <string>())).Returns(responseTask2);
            TheatresController theatresController = new TheatresController(_theatreService.Object, _addressService.Object);

            //Act
            var result          = theatresController.PostAsync(createTheatreModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var badObjectResult = ((BadRequestObjectResult)result).Value;
            var errorResult     = (ErrorResponseModel)badObjectResult;

            //Assert
            Assert.IsNotNull(errorResult);
            Assert.AreEqual(expectedMessage, errorResult.ErrorMessage);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual(expectedStatusCode, ((BadRequestObjectResult)result).StatusCode);
        }
예제 #6
0
        public async Task WhenAddressInIsValid_ThenResult_ShouldBeFalse()
        {
            var svc = new AddressService(new UspsAddressValidationService(_options), _httpClientFactory);
            var addressDomainModel = new AddressDomainModel
            {
                City       = "Chicago",
                State      = "NE",
                PostalCode = "10101",
                Line1      = "233 S. Wacker Dr."
            };

            var result = await svc.ValidAddressAsync(addressDomainModel);

            Assert.False(result);
        }
        public void PostAsync_Create_IsSuccessful_True_Theatre()
        {
            //Arrange
            int expectedStatusCode = 201;

            CreateTheatreModel createTheatreModel = new CreateTheatreModel()
            {
                Name          = "bioskop123",
                CityName      = "grad",
                SeatRows      = 15,
                NumberOfSeats = 11,
                AuditName     = "Sala1"
            };

            AddressDomainModel addressDomainModel = new AddressDomainModel
            {
                Id         = 123,
                CityName   = "grad123",
                StreetName = "ulica123"
            };

            TheatreDomainModel theatreDomainModel = new TheatreDomainModel
            {
                AddressId       = 1234,
                Name            = createTheatreModel.Name,
                AuditoriumsList = new List <AuditoriumDomainModel>()
            };

            Task <TheatreDomainModel> responseTask  = Task.FromResult(theatreDomainModel);
            Task <AddressDomainModel> responseTask2 = Task.FromResult(addressDomainModel);

            _theatreService = new Mock <ITheatreService>();
            _addressService = new Mock <IAddressService>();
            _addressService.Setup(x => x.GetByCityNameAsync(It.IsAny <string>())).Returns(responseTask2);
            _theatreService.Setup(x => x.Create(It.IsAny <TheatreDomainModel>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(responseTask);
            TheatresController theatreController = new TheatresController(_theatreService.Object, _addressService.Object);


            //Act
            var result               = theatreController.PostAsync(createTheatreModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var createdResult        = ((CreatedResult)result).Value;
            var theatreReturnedModel = (TheatreDomainModel)createdResult;

            //Assert
            Assert.IsNotNull(theatreReturnedModel);
            Assert.IsInstanceOfType(result, typeof(CreatedResult));
            Assert.AreEqual(expectedStatusCode, ((CreatedResult)result).StatusCode);
        }
예제 #8
0
 /// <summary>
 /// Maps the domain address model to USPS format
 /// </summary>
 /// <param name="address"></param>
 /// <param name="userId"></param>
 /// <returns></returns>
 public static AddressValidateRequest ToAddressValidateRequest(this AddressDomainModel address, string userId)
 {
     return(new AddressValidateRequest
     {
         Address = new AddressXML
         {
             Address1 = address.Line1,
             Address2 = "",
             City = address.City,
             Id = "0",
             State = address.State,
             Zip4 = "",
             Zip5 = address.PostalCode
         },
         UserId = userId
     });
 }
예제 #9
0
        public async Task <AddressDomainModel> GetByCityNameAsync(string cityName)
        {
            var city = await _addressesRepository.GetByCityNameAsync(cityName);

            if (city == null)
            {
                return(null);
            }

            AddressDomainModel addressDomainModel = new AddressDomainModel
            {
                Id         = city.Id,
                CityName   = city.CityName,
                StreetName = city.StreetName
            };

            return(addressDomainModel);
        }
예제 #10
0
        public async Task <AddressDomainModel> GetByIdAsync(int id)
        {
            var address = await _addressesRepository.GetByIdAsync(id);

            if (address == null)
            {
                return(null);
            }

            AddressDomainModel addressDomainModel = new AddressDomainModel
            {
                Id         = address.Id,
                CityName   = address.CityName,
                StreetName = address.StreetName
            };

            return(addressDomainModel);
        }
        public void PostAsync_Create_IsSuccessful_False_Return_BadRequest()
        {
            //Arrange
            string expectedMessage    = Messages.THEATRE_CREATION_ERROR;
            int    expectedStatusCode = 400;

            CreateTheatreModel createTheatreModel = new CreateTheatreModel
            {
                Name          = "bioskop",
                CityName      = "grad",
                NumberOfSeats = 13,
                SeatRows      = 13,
                AuditName     = "Sala12"
            };

            AddressDomainModel addressDomainModel = new AddressDomainModel
            {
                Id         = 123,
                CityName   = "grad123",
                StreetName = "ulica123"
            };

            TheatreDomainModel        theatreDomainModel = null;
            Task <TheatreDomainModel> responseTask       = Task.FromResult(theatreDomainModel);
            Task <AddressDomainModel> responseTask2      = Task.FromResult(addressDomainModel);

            _theatreService = new Mock <ITheatreService>();
            _addressService = new Mock <IAddressService>();
            _addressService.Setup(x => x.GetByCityNameAsync(It.IsAny <string>())).Returns(responseTask2);
            _theatreService.Setup(x => x.Create(It.IsAny <TheatreDomainModel>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(responseTask);
            TheatresController theatresController = new TheatresController(_theatreService.Object, _addressService.Object);

            //Act
            var result          = theatresController.PostAsync(createTheatreModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var badObjectResult = ((BadRequestObjectResult)result).Value;
            var errorResult     = (ErrorResponseModel)badObjectResult;

            //Assert
            Assert.IsNotNull(errorResult);
            Assert.AreEqual(expectedMessage, errorResult.ErrorMessage);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual(expectedStatusCode, ((BadRequestObjectResult)result).StatusCode);
        }
예제 #12
0
        public void TestInitialize()
        {
            List <Address> address = new List <Address>();
            List <Theatre> theatre = new List <Theatre>();

            _address = new Address
            {
                CityName   = "Zrenjanin",
                Id         = 1,
                StreetName = "Cara Dusana 1"
            };
            _addressDomainModel = new AddressDomainModel
            {
                CityName   = _address.CityName,
                Id         = _address.Id,
                StreetName = _address.StreetName
            };

            _mockAddressesRepository = new Mock <IAddressesRepository>();
            _addressService          = new AddressService(_mockAddressesRepository.Object);
        }
예제 #13
0
        public async Task <ActionResult> Post([FromBody] AddressModel addressModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            AddressDomainModel domainModel = new AddressDomainModel
            {
                CityName   = addressModel.CityName,
                StreetName = addressModel.StreetName
            };

            AddressDomainModel createAddress;

            try
            {
                createAddress = await _addressService.AddAddress(domainModel);
            }
            catch (DbUpdateException e)
            {
                ErrorResponseModel errorResponse = new ErrorResponseModel
                {
                    ErrorMessage = e.InnerException.Message ?? e.Message,
                    StatusCode   = System.Net.HttpStatusCode.BadRequest
                };
                return(BadRequest(errorResponse));
            }
            if (createAddress == null)
            {
                ErrorResponseModel errorResponse = new ErrorResponseModel
                {
                    ErrorMessage = Messages.ADDRESS_CREATION_ERROR,
                    StatusCode   = System.Net.HttpStatusCode.InternalServerError
                };
                return(BadRequest(errorResponse));
            }
            return(CreatedAtAction(nameof(GetAddressById), new { Id = createAddress.Id }, createAddress));
        }
        public void GetAddress_ById_Async_Return_Not_Found()
        {
            //Arrange
            string                    expectedMessage    = Messages.ADDRESS_NOT_FOUND;
            int                       expectedStatusCode = 404;
            AddressDomainModel        addressDomainModel = null;
            Task <AddressDomainModel> responseTask       = Task.FromResult(addressDomainModel);

            _addressService = new Mock <IAddressService>();
            _addressService.Setup(x => x.GetByIdAsync(It.IsAny <int>())).Returns(responseTask);
            AddressesController addressController = new AddressesController(_addressService.Object);

            //Act
            var    result       = addressController.GetAddressById(123).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var    objectResult = ((NotFoundObjectResult)result).Value;
            string message      = (string)objectResult;

            //Assert
            Assert.IsNotNull(objectResult);
            Assert.IsInstanceOfType(result, typeof(NotFoundObjectResult));
            Assert.AreEqual(expectedStatusCode, ((NotFoundObjectResult)result).StatusCode);
            Assert.AreEqual(expectedMessage, message);
        }
예제 #15
0
        public async Task <AddressDomainModel> AddAddress(AddressDomainModel addressModel)
        {
            Address createAddress = new Address()
            {
                CityName   = addressModel.CityName,
                StreetName = addressModel.StreetName,
            };

            Address data = _addressesRepository.Insert(createAddress);

            if (data == null)
            {
                return(null);
            }

            _addressesRepository.Save();

            return(new AddressDomainModel
            {
                CityName = data.CityName,
                StreetName = data.StreetName
            });
        }
예제 #16
0
        public async Task <IEnumerable <AddressDomainModel> > GetAllAsync()
        {
            var addresses = await _addressesRepository.GetAllAsync();

            if (addresses.Count() == 0)
            {
                return(null);
            }

            List <AddressDomainModel> addressDomainModels = new List <AddressDomainModel>();

            foreach (var address in addresses)
            {
                AddressDomainModel addressDomainModel = new AddressDomainModel
                {
                    Id         = address.Id,
                    CityName   = address.CityName,
                    StreetName = address.StreetName
                };
                addressDomainModels.Add(addressDomainModel);
            }

            return(addressDomainModels);
        }
예제 #17
0
        /// <summary>
        /// Converts an address domain model to an XML string
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        private string GetAddressAsXml(AddressDomainModel addressDomainModel)
        {
            var addressValidateRequest = addressDomainModel.ToAddressValidateRequest(_options.Value.UserName);

            return(XmlSerializationUtility.GetXmlString(addressValidateRequest));
        }
예제 #18
0
        public string CreateRequest(AddressDomainModel addressDomainModel)
        {
            var addressXml = GetAddressAsXml(addressDomainModel);

            return(BuildAddressValidationUrl(addressXml));
        }