public Location CreateLocation(CreateLocationModel model) { var entity = model.ToDest(); PrepareCreate(entity); return(context.Location.Add(entity).Entity); }
public void StateSelectList_DataDriven_XmlFile_DetermineIfListHasCorrectValuesInCorrectOrder() { // Arrange // stateFullName, stateAbbreviaion var stateFullName = Convert.ToString(TestContext.DataRow["fullName"]); var stateAbbreviation = Convert.ToString(TestContext.DataRow["abbreviation"]); var statePositionInDropdown = Convert.ToInt32(TestContext.DataRow["positionInDropdown"]); const int expectedNumberOfItems = 7; // First Act var myCreateLocationModel = new CreateLocationModel(); var result = myCreateLocationModel.StateSelectList; // First Assert Assert.IsNotNull(result, "result is null"); Assert.IsTrue(result is SelectList, "result is not SelectList"); // Second Act var resultSelectList = result as SelectList; // Second Assert Assert.IsNotNull(resultSelectList, "resultSelectList is null"); Assert.AreEqual(expectedNumberOfItems, resultSelectList.Count(), "resultSelectList Items count"); // Third Act var individualItem = resultSelectList.ElementAt(statePositionInDropdown - 1); // Third Assert Assert.AreEqual(stateFullName, individualItem.Text, "State Full Name doesn't match"); Assert.AreEqual(stateAbbreviation, individualItem.Value, "State Abbreviation doesn't match"); }
public async Task ShouldCreateNewLocationObject() { // Arrange var testServer = TestUtil.CreateTestServer(); var testClient = testServer.CreateClient(); var newLocation = new CreateLocationModel() { Name = "Loyola University", StreetAddress = "6430 Kenmore Ave", City = "Chicago", State = "IL", ZipCode = "60626" }; // Act var response = await testClient.PostAsJsonAsync <CreateLocationModel>("/api/Locations", newLocation); // Assert response.StatusCode.Should().BeEquivalentTo(HttpStatusCode.Created); var model = await response.Content.ReadAsAsync <LocationModel>(); model.LocationName.Should().Be("Loyola University"); // Confirm var confirmResponse = await testClient.GetAsync("/api/Locations"); confirmResponse.StatusCode.Should().BeEquivalentTo(HttpStatusCode.OK); var confirmModels = await confirmResponse.Content.ReadAsAsync <List <LocationModel> >(); confirmModels.Count.Should().Be(5); }
public IActionResult Post([FromBody] CreateLocationModel createModel) { var createLocationCommand = this.mapper.Map <CreateLocationModel, CreateLocationCommand>(createModel); Location location = this.locationService.CreateLocation(createLocationCommand); var model = this.mapper.Map <Location, LocationModel>(location); return(this.CreatedAtRoute("GetLocationById", new { id = location.LocationId }, model)); }
public async Task <int> Execute(int userId, CreateLocationModel createLocationModel) { if ((string.IsNullOrEmpty(createLocationModel.Label)) || (string.IsNullOrEmpty(createLocationModel.Remark))) { return(-1); } else { return(await _createLocationCommand.Execute(userId, createLocationModel)); } }
public LocationModelValidatorTest() { _locationOne = new CreateLocationModel() { Name = "US Bank Building", StreetAddress = "777 E Wisconsin Ave", City = "Milwaukee", State = "WI", ZipCode = "53202" }; }
public void TestInitialize() { userId = 1; createLocationModel = new CreateLocationModel() { Label = "Argentina", Latitude = 3.56D, Longitude = 7.76D, Remark = "Beautiful and charming" }; _createLocationCommand = new Mock <ICreateLocationCommand>(); _createLocation = new CreateLocation(_createLocationCommand.Object); }
public IActionResult Create(CreateLocationModel model) { var validationResult = _service.ValidateCreateLocation(User, model); if (!validationResult.Valid) { return(BadRequest(validationResult.Result)); } var entity = _service.CreateLocation(model); context.SaveChanges(); return(Created($"/{ApiEndpoint.LOCATION_API}?id={entity.Id}", new AppResultBuilder().Success(entity.Id))); }
// POST: api/LocationsAPI //[ResponseType(typeof(CreateLocationModel))] public async Task <IActionResult> PostLocation(CreateLocationModel createLocationModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //createLocationModel.VMEntity.WorldId = createLocationModel.WorldId; db.Entities.Add(createLocationModel.VMEntity); createLocationModel.VMLocation.Entity = createLocationModel.VMEntity; db.Locations.Add(createLocationModel.VMLocation); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = createLocationModel.VMLocation.LocationId }, createLocationModel.VMLocation)); }
public void ValidLocationObjectsShouldPass(string name, string address, string city, string state, string zipCode) { // Arrange CreateLocationModel model = new CreateLocationModel() { Name = name, StreetAddress = address, City = city, State = state, ZipCode = zipCode }; // Act CreateLocationModelValidator validator = new CreateLocationModelValidator(); var result = validator.Validate(model); // Assert result.IsValid.Should().BeTrue(); }
public void CreateLocation_MaxBandwidthIsOverLimit_Failed_ValidateError() { try { // new subscriber data var loc = DataHelper.NewLocationData(); loc.MaximumBandwidth = "1234"; // initialize CreateSubscriberModel var createLocModel = new CreateLocationModel { LocationID = loc.ID, Address1 = loc.AddressLine1, City = loc.AddressLine1, State = loc.StateName, ZipCode = loc.ZipCode, MaxBandwidth = loc.MaximumBandwidth, }; // call CreateLocation action method var result = SearchControllerForTest.CreateLocation(createLocModel) as JsonResult; // validate result Assert.IsNotNull(result, "Json result is null"); Assert.IsNotNull(result.Data, "Json result data is null"); // expected result const string expectedError = "[MaxBandwidth] value invalid:"; // validate actual json contains expected error var jss = new JavaScriptSerializer(); var actualJson = jss.Serialize(result.Data.ToJSON()); Assert.IsTrue(actualJson.Contains(expectedError)); } catch (Exception ex) { Assert.IsTrue(ex is AssertFailedException, ex.ToString()); throw; } }
public void CreateLocation_With_Address_NetworkLocationCode_RateCenter_MaxBandwidth_ValidateUserAbleToCreateLocation() { var loc = new LocationDto(); try { // Given a user that has permission to create new location // And a new location with all valid info // And the new location has a valid address loc = DataHelper.NewLocationData(); // And the new location has a valid max bandwidth loc.MaximumBandwidth = "20"; // And the new location has a valid network location code loc.NetworkLocationCode = "1234567"; // And the new location has a valid rate center name loc.RateCenterName = "washington"; var createLocModel = new CreateLocationModel { LocationID = loc.ID, Address1 = loc.AddressLine1, Address2 = loc.AddressLine2, City = loc.CityName, State = loc.StateName, ZipCode = loc.ZipCode, MaxBandwidth = loc.MaximumBandwidth, NetworkLocationCode = loc.NetworkLocationCode, RateCenter = loc.RateCenterName }; // When creating new location with the valid location info var actionResult = SearchControllerForTest.CreateLocation(createLocModel) as JsonResult; // Then the user receives a response Assert.IsNotNull(actionResult, "Json result is null"); Assert.IsNotNull(actionResult.Data, "Json result data is null"); // And the response is successful var jss = new JavaScriptSerializer(); var expectedResult = new { status = "valid", isModal = false, newLocationID = loc.ID }.ToJSON(); Assert.AreEqual(jss.Serialize(expectedResult), jss.Serialize(actionResult.Data.ToJSON())); // And the new location created in provisioning system var actualLoc = DataHelper.LoadLocation(loc.ID); Assert.IsNotNull(actualLoc, "Location should not be null!"); Assert.AreEqual(loc.ID, actualLoc.ID, "Location ID does not match!"); // And the new location created with the requested addresses Assert.AreEqual(loc.AddressLine1, actualLoc.AddressLine1, "Address1 does not match"); Assert.AreEqual(loc.AddressLine2, actualLoc.AddressLine2, "Address2 does not match"); Assert.AreEqual(loc.CityName, actualLoc.CityName, "CityName does not match"); Assert.AreEqual(loc.StateName, actualLoc.StateName, "StateName does not match"); Assert.AreEqual(loc.ZipCode, actualLoc.ZipCode, "ZipCode does not match"); // And the new location created with the requested max bandwidth Assert.AreEqual(loc.MaximumBandwidth, actualLoc.MaximumBandwidth, "MaximumBandwidth does not match"); // And the new location created with the requested NetworkLocationCode Assert.AreEqual(loc.NetworkLocationCode, actualLoc.NetworkLocationCode, true,"NetworkLocationCode does not match"); // And the new location created with the requested RateCenterName Assert.AreEqual(loc.RateCenterName, actualLoc.RateCenterName, true,"Rate Center does not match"); } catch (Exception ex) { Assert.IsTrue(ex is AssertFailedException, ex.ToString()); throw; } finally { DataHelper.DeleteLocation(loc.ID); } }
[ValidateUserExists] //Validates the user existence before jumping into locations query. This method can be reused. public async Task <IActionResult> PostLocation([FromRoute] int userId, [FromBody] CreateLocationModel createLocationModel) { var result = await _createLocation.Execute(userId, createLocationModel); return(Ok(result)); }
public void User_Attempts_To_create_a_new_location_with_correct_data_and_an_error_is_returned() { using (ShimsContext.Create()) { //Arrange // Given a user that has permission to create new location ShimCurrentUser.AsUserDto = new SIMPLTestContext().GetFakeUserDtoObject; // And the new location to be created var createLocModel = new CreateLocationModel { LocationID = "1234567", Address1 = "MYADDRESS1", Address2 = "MYADDRESS2", City = "MYCITY", State = "MYSTATE", ZipCode = "MYZIPCODE", MaxBandwidth = "25", NetworkLocationCode = "MYNETWORKLOCATIONCODE", RateCenter = "MYRATECENTER" }; var searchController = DependencyResolver.Current.GetService<SearchController>(); //This is for creating a Fault exception const string expectedErrorMessage = "This is a fault exception message"; var faultDetail = new ValidationDetailDto() { Message = expectedErrorMessage }; var faultDetails = new List<ValidationDetailDto>(); faultDetails.Add(faultDetail); var validationFault = new ValidationFaultDto() { Details = faultDetails }; var fault = new FaultException<ValidationFaultDto>(validationFault); //Have Controller CreateLocation method throw the fault when called ShimRosettianClient.AllInstances.CreateLocationLocationDtoUserDto = delegate { throw fault; }; //Act //Call the actual controller method var actionResponse = searchController.CreateLocation(createLocModel) as JsonResult; //Assert // Then the user receives a response Assert.IsNotNull(actionResponse, "CreateLocation json result is null"); Assert.IsNotNull(actionResponse.Data, "CreateLocation json result data is null"); // And the expected response is a Fault exception var jss = new JavaScriptSerializer(); var expectedResult = new { status = "error", isModal = false, errorMessage = "This is a fault exception message" }.ToJSON(); Assert.AreEqual(jss.Serialize(expectedResult), jss.Serialize(actionResponse.Data.ToJSON())); } }
public ValidationResult ValidateCreateLocation(ClaimsPrincipal principal, CreateLocationModel model) { return(ValidationResult.Pass()); }
public void User_attempts_to_create_a_new_location_with_correct_data_and_an_non_Rosettian_error_is_returned() { using (ShimsContext.Create()) { //Arrange // Given a user that has permission to create new location ShimCurrentUser.AsUserDto = new SIMPLTestContext().GetFakeUserDtoObject; // And the new location to be created has max bandwidth over limited var createLocModel = new CreateLocationModel { LocationID = "1234567", Address1 = "MYADDRESS1", Address2 = "MYADDRESS2", City = "MYCITY", State = "MYSTATE", ZipCode = "MYZIPCODE", MaxBandwidth = "25", NetworkLocationCode = "MYNETWORKLOCATIONCODE", RateCenter = "MYRATECENTER" }; // When creating new location ShimRosettianClient.AllInstances.CreateLocationLocationDtoUserDto = (myClient, mySubscriberDto, myUserDto) => { }; //Create a non-Fault exception const string exceptionMessage = "This is my argument exception"; ShimLocationExtension.MapToNewLocationCreateLocationModel = delegate { throw new ArgumentException(exceptionMessage); }; //Act var searchController = DependencyResolver.Current.GetService<SearchController>(); var actionResponse = searchController.CreateLocation(createLocModel) as JsonResult; //Assert // Then the user receives a response Assert.IsNotNull(actionResponse, "CreateLocation json result is null"); Assert.IsNotNull(actionResponse.Data, "CreateLocation json result data is null"); // And the response is successful var jss = new JavaScriptSerializer(); var expectedResult = new { status = "error", isModal = false, errorMessage = exceptionMessage }.ToJSON(); Assert.AreEqual(jss.Serialize(expectedResult), jss.Serialize(actionResponse.Data.ToJSON())); } }
public void CreateLocation_MaxBandwidthIsOverLimit_ValidateUserReceivesError() { using (ShimsContext.Create()) { // Given a user that has permission to create new location ShimCurrentUser.AsUserDto = new SIMPLTestContext().GetFakeUserDtoObject; // And the new location to be created has max bandwidth over limited var createLocModel = new CreateLocationModel { LocationID = "1234567", Address1 = "MYADDRESS1", City = "MYCITY", State = "MYSTATE", ZipCode = "MYZIPCODE", MaxBandwidth = "100", }; const string expectedError = "[MaxBandwidth] value invalid:"; // When creating new location with the over limited max bandwidth ShimRosettianClient.AllInstances.CreateLocationLocationDtoUserDto = (myClient, myLocationDto, myUserDto) => { throw new Exception(expectedError); }; var searchController = DependencyResolver.Current.GetService<SearchController>(); var actionResult = searchController.CreateLocation(createLocModel) as JsonResult; // Then the user receives a response Assert.IsNotNull(actionResult, "Json result is null"); Assert.IsNotNull(actionResult.Data, "Json result data is null"); // And the response is an error // And the error tells user the max bandwidth value invalid var jss = new JavaScriptSerializer(); var actualJson = jss.Serialize(actionResult.Data.ToJSON()); Assert.IsTrue(actualJson.Contains(expectedError)); } }
public void CreateLocation_With_Address_NetworkLocationCode_RateCenter_MaxBandwidth_ValidateUserAbleToCreateLocation() { using (ShimsContext.Create()) { // Given a user that has permission to create new location ShimCurrentUser.AsUserDto = new SIMPLTestContext().GetFakeUserDtoObject; // And the new location has a valid address // And the new location has a valid max bandwidth // And the new location has a valid network location code // And the new location has a valid rate center name var createLocModel = new CreateLocationModel { LocationID = "1234567", Address1 = "MYADDRESS1", Address2 = "MYADDRESS2", City = "MYCITY", State = "MYSTATE", ZipCode = "MYZIPCODE", MaxBandwidth = "25", NetworkLocationCode = "MYNETWORKLOCATIONCODE", RateCenter = "MYRATECENTER" }; // When creating new location with the valid location info ShimRosettianClient.AllInstances.CreateLocationLocationDtoUserDto = (myClient, myLocationDto, myUserDto) => { }; var searchController = DependencyResolver.Current.GetService<SearchController>(); var actionResult = searchController.CreateLocation(createLocModel) as JsonResult; // Then the user receives a response Assert.IsNotNull(actionResult, "Json result is null"); Assert.IsNotNull(actionResult.Data, "Json result data is null"); // And the response is successful var jss = new JavaScriptSerializer(); var expectedResult = new { status = "valid", isModal = false, newLocationID = createLocModel.LocationID }.ToJSON(); Assert.AreEqual(jss.Serialize(expectedResult), jss.Serialize(actionResult.Data.ToJSON())); } }