public void TestONTActionResult_DefaultNullCanGetSet() { var response = new RozResponseDto() { Code = "200", Message = "OK" }; Assert.IsNull(_model.ONTActionResult); _model.ONTActionResult = response; Assert.IsNotNull(_model.ONTActionResult); Assert.AreEqual("200", _model.ONTActionResult.Code); Assert.AreEqual("OK", _model.ONTActionResult.Message); }
public void ClearLocation_Succeed() { var loc = new LocationDto(); var sub = new SubscriberDto(); try { // new sub and loc data loc = DataHelper.NewLocationData(); loc.RateCenterName = "WASHINGTON"; loc.NetworkLocationCode = "1234567"; sub = DataHelper.NewSubscriberData(); sub.Accounts[0].Location = loc; sub.CustomFields = DataHelper.DefaultCustomFields_Sub(); DataHelper.RestoreLocation1(loc, false); DataHelper.RestoreSubscriber1(sub, false); // set current subscriber CurrentSubscriber.SetInstance(sub); // call ClearLocation action method var actualResult = LocationController4Tests.ClearLocation(loc.ID) as PartialViewResult; // validate returned result and model are not null Assert.IsTrue(actualResult != null && actualResult.Model != null); // validate model var resultModel = actualResult.Model as SubscriberLocationModel; Assert.IsNotNull(resultModel, "Model should not be null"); // validate returned action response var expectedActionResponse = new RozResponseDto { Code = "200", Message = String.Format("Successfully disassociated subscriber from location [{0}]", loc.ID) }; Assert.IsNotNull(resultModel.ActionResponse, "ActionResponse should not be null"); Assert.AreEqual(expectedActionResponse.Code, resultModel.ActionResponse.Code); Assert.AreEqual(expectedActionResponse.Message, resultModel.ActionResponse.Message); // validate location cleared for subscriber in db var actualSub = DataHelper.LoadSubscriber(sub.ID); Assert.IsTrue(actualSub!=null && actualSub.Accounts.Any() && actualSub.Accounts[0]!=null); Assert.IsTrue(actualSub.Accounts[0].Location == null || string.IsNullOrEmpty(actualSub.Accounts[0].Location.ID)); } catch (Exception ex) { Assert.IsTrue(ex is AssertFailedException, ex.ToString()); throw; } finally { DataHelper.DeleteSubscriber(sub.ID); DataHelper.DeleteLocation(loc.ID); } }
public void ChangeLocation_Succeed() { var loc = new LocationDto(); var loc2 = new LocationDto(); var sub = new SubscriberDto(); try { // new sub and loc data loc = DataHelper.NewLocationData(); loc.RateCenterName = "WASHINGTON"; loc.NetworkLocationCode = "1234567"; loc2 = DataHelper.NewLocationData(); loc2.RateCenterName = "STAMFORD"; loc2.NetworkLocationCode = "2345668"; sub = DataHelper.NewSubscriberData(); sub.Accounts[0].Location = loc; sub.CustomFields = DataHelper.DefaultCustomFields_Sub(); DataHelper.RestoreLocation1(loc, false); DataHelper.RestoreSubscriber1(sub, false); DataHelper.RestoreLocation1(loc2, false); // set current subscriber CurrentSubscriber.SetInstance(sub); var loc2AsJson = JavaScriptSerializerUtil.Serialize(loc2); // call ChangeLocation action method var actualResult = LocationController4Tests.ChangeLocation(loc2AsJson) as PartialViewResult; // validate returned result and model are not null Assert.IsTrue(actualResult != null && actualResult.Model != null); // validate model var resultModel = actualResult.Model as SubscriberLocationModel; Assert.IsNotNull(resultModel, "Model should not be null"); // validate returned action response var expectedActionResponse = new RozResponseDto { Code = "200", Message = string.Format("Successfully changed location from [{0}] to [{1}] for subscriber [{2}]", loc.ID, loc2.ID, sub.ID) }; Assert.IsNotNull(resultModel.ActionResponse, "ActionResponse should not be null"); Assert.AreEqual(expectedActionResponse.Code, resultModel.ActionResponse.Code); Assert.AreEqual(expectedActionResponse.Message, resultModel.ActionResponse.Message); // validate location changed for subscriber in db var actualSub = DataHelper.LoadSubscriber(sub.ID); Assert.AreEqual(loc2.ID, actualSub.Accounts[0].Location.ID, "Subscriber location id does not match"); } catch (Exception ex) { Assert.IsTrue(ex is AssertFailedException, ex.ToString()); throw; } finally { DataHelper.DeleteSubscriber(sub.ID); DataHelper.DeleteLocation(loc.ID); DataHelper.DeleteLocation(loc2.ID); } }
public void LoadEquipment_DeviceIdInvalid_ValidateUserReceivesError() { using (ShimsContext.Create()) { // Given a user ShimCurrentUser.AsUserDto = () => new SIMPLTestContext().GetFakeUserDtoObject(); // And an invalid equipment id const string nonExistEquipId = "EquipIdDoesNotExist"; // And there is no subscriber found with that invalid equipment id ShimRosettianClient.AllInstances.SearchSubscribersSearchFieldsDtoUserDto = (myTestClient, mySearchCriteria, myUserDto) => new List<SubscriberDto>(); // And there is no location found with the non exist equipment id ShimRosettianClient.AllInstances.SearchLocationsSearchFieldsDtoUserDto = (myTestClient, mySearchCriteria, myUserDto) => new LocationCollectionDto(); // When loading that equipment var actionResult = SubscriberControllerForTests.LoadEquipment(nonExistEquipId) as ViewResult; // Then the user receives a response Assert.IsNotNull(actionResult, "SubscriberController LoadEquipment method returned null"); Assert.IsNotNull(actionResult.ViewData, "actionResult.ViewData is null"); // And the response is an error Assert.AreEqual("Index2", actionResult.ViewName, "ViewName does not match"); var actualModel = actionResult.Model as SubscriberModel; Assert.IsNotNull(actualModel, "Model was null"); // And the error message tells user no results from search on that equipment id var jss = new JavaScriptSerializer(); var expectedActionResponse = new RozResponseDto() { Code = "500", Message = string.Format("No results from search on equipment ID = {0}", nonExistEquipId) }; Assert.AreEqual(jss.Serialize(expectedActionResponse), jss.Serialize(actualModel.ActionResponse), ""); } }