//TODO Package these categories and do this test with a reference to the package public void Get_WhenValidSortTypeIsRequested_ExpectOkResponse(string sortType) { var result = recordsController.Get(sortType); // Assert Assert.That(result, Is.TypeOf <OkNegotiatedContentResult <IList <Record> > >()); }
public void TestGetAll() { controller.Post(r1); controller.Post(r1); controller.Post(r1); Assert.AreEqual(3, controller.Get().Count()); }
public void RecordsControllerGetShouldReturnSortedByGenderList() { //arrange string sortby = "gender"; IList <Person> unsortedList = _controller._parserServiceWrapper.PersonCache; //act IList <Person> sortedList = _controller.Get(sortby); var first = sortedList.FirstOrDefault(); var last = sortedList.LastOrDefault(); //assert Assert.AreEqual("Connichie", first.LastName); Assert.AreEqual("Whiteside", last.LastName); }
public void Get_Url_Throw_NotFound() { // Arrange Mock <IHistoryRecordService> mock = new Mock <IHistoryRecordService>(); mock.Setup(m => m.GetHistoryRecord(It.IsAny <long>())).Returns((HistoryRecord)null); var historyRecordService = mock.Object; var controller = new RecordsController(historyRecordService); SetupControllerForTests(controller); string hash = "70y856ilox"; // Act try { var result = controller.Get(hash); } // Assert catch (HttpResponseException ex) { Assert.AreEqual(System.Net.HttpStatusCode.NotFound, ex.Response.StatusCode); throw; } }
public async void GetAllReturnsTwoResults() { var records = new[] { new Models.Record { Id = "1", Value = "Value 1" }, new Models.Record { Id = "2", Value = "Value 2" } }; var mockRecordRepository = new Mock <IRecordRepository>(); mockRecordRepository .Setup(p => p.GetAll()) .Returns(async() => { await Task.Yield(); return(records); }); var recordRepository = mockRecordRepository.Object; var target = new RecordsController(recordRepository); var result = await target.Get(); Assert.IsAssignableFrom <ObjectResult>(result); var expected = JsonConvert.SerializeObject(new { items = records }); Assert.Equal(expected, JsonConvert.SerializeObject(((ObjectResult)result).Value)); }
public void cloned_record_should_have_null_publication() { var record = new Record { Id = new Guid("736532c8-9b3d-4524-86ac-248e0476fa38"), Path = @"X:\some\path", Gemini = Library.Blank().With(m => m.Title = "Some new record!"), Publication = new PublicationInfo { OpenData = new OpenDataPublicationInfo { Assessment = new OpenDataAssessmentInfo { Completed = true } } } }; var db = Mock.Of <IDocumentSession>(d => d.Load <Record>(It.IsAny <Guid>()) == record); var service = Mock.Of <IRecordService>(); var controller = new RecordsController(service, db, new TestUserContext()); var result = (RecordOutputModel)controller.Get(record.Id, true); result.Record.Id.Should().BeEmpty(); result.Record.Path.Should().BeEmpty(); result.Record.Gemini.Title.Should().BeEmpty(); result.Record.Publication.Should().BeNull(); }
public void should_return_blank_record_for_empty_guid() { var controller = new RecordsController(Mock.Of <IRecordService>(), Mock.Of <IDocumentSession>(), new TestUserContext()); var recordResult = (RecordOutputModel)controller.Get(Guid.Empty); recordResult.Record.Gemini.Title.Should().BeBlank(); recordResult.Record.Path.Should().BeBlank(); }
public void GetTest() { //arrange List <record> listRecord = new List <record>(); { }; //action foreach (record Records in rntr.Get()) { listRecord.Add(Records); } //assert Assert.AreEqual(2, listRecord.Count); }
public void Get_InvalidResponse_SortFieldDoesntExists() { var controller = new RecordsController(); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); var response = controller.Get("Unkown"); Assert.AreEqual(response.IsSuccessStatusCode, false); }
public void Get_ValidResponse_SortFieldExists() { var controller = new RecordsController(); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); var response = controller.Get("Gender"); Assert.AreEqual(response.IsSuccessStatusCode, true); }
public void InvalidInputUnitTest() { // Arrange RecordsController controller = new RecordsController(); // Act PostInvalid(ref controller); // attempt to insert invalid results var resultBirthdateJSON = controller.Get("birthdate"); var resultBirthdate = JsonConvert.DeserializeObject <List <Record> >(resultBirthdateJSON); //Assert Assert.IsNotNull(resultBirthdate); Assert.AreEqual(0, resultBirthdate.Count()); }
public void Get_NotFound() { // Arrange var mapper = Substitute.For <IMapper>(); var repo = Substitute.For <IRepository>(); var logger = Substitute.For <ILogger <RecordsController> >(); var target = new RecordsController(repo, logger, mapper); // Act var result = target.Get("testAppName", "dataType", "version1").Result; // Assert Assert.IsType <NotFoundObjectResult>(result); }
public void Get() { // Arrange RecordsController controller = new RecordsController(); RecordsController.pdir.Plist = new List <ClassLibrary.PersonInfo>(); controller.Post("smith, edward, male, yellow, 5/20/2000"); controller.Post("thomas, edward, male, purple, 2/16/2001"); controller.Post("fox, sue, female, green, 1/18/1990"); controller.Post("fox, kelly, female, brown, 8/05/1992"); controller.Post("laflin, stephen, male, burgandy, 09/02/2000"); List <string> expctd = new List <string> { "fox, kelly, female, brown, 8/5/1992", "fox, sue, female, green, 1/18/1990", "laflin, stephen, male, burgandy, 9/2/2000", "smith, edward, male, yellow, 5/20/2000", "thomas, edward, male, purple, 2/16/2001" }; // Act List <string> result = controller.Get("name").ToList(); bool match = true; if (expctd.Count != result.Count) { match = false; } if (match) { for (int cntr = 0; cntr < expctd.Count; cntr++) { if (expctd[cntr] != result[cntr]) { match = false; break; } } } // Assert Assert.AreEqual(true, match); }
public void GenderTest() { // Arrange RecordsController controller = new RecordsController(); // Act PostValid(ref controller); // insert valid results (6 records) PostInvalid(ref controller); // attempt to insert invalid results var resultJSON = controller.Get("gender"); var resultGender = JsonConvert.DeserializeObject <List <Record> >(resultJSON); //Assert Assert.IsNotNull(resultGender); Assert.AreNotEqual(0, resultGender.Count()); Assert.AreEqual(6, resultGender.Count()); Assert.IsTrue(resultGender.First().Gender[0] == 'f' || resultGender.First().Gender[0] == 'F'); Assert.IsTrue(resultGender.Last().Gender[0] == 'm' || resultGender.Last().Gender[0] == 'M'); }
public void LastNameTest() { // Arrange RecordsController controller = new RecordsController(); // Act PostValid(ref controller); // insert valid results (6 records) PostInvalid(ref controller); // attempt to insert invalid results var resultLastnameJSON = controller.Get("name"); var resultLastname = JsonConvert.DeserializeObject <List <Record> >(resultLastnameJSON); //Assert Assert.IsNotNull(resultLastname); Assert.AreNotEqual(0, resultLastname.Count()); Assert.AreEqual(6, resultLastname.Count()); Assert.AreEqual("Zebedane", resultLastname.First().LastName); Assert.AreEqual("Cooper", resultLastname.Last().LastName); }
public void BirthdateTest() { // Arrange RecordsController controller = new RecordsController(); // Act PostValid(ref controller); // insert valid results (6 records) PostInvalid(ref controller); // attempt to insert invalid results var resultBirthdateJSON = controller.Get("birthdate"); var resultBirthdate = JsonConvert.DeserializeObject <List <Record> >(resultBirthdateJSON); //Assert Assert.IsNotNull(resultBirthdate); Assert.AreNotEqual(0, resultBirthdate.Count()); Assert.AreEqual(6, resultBirthdate.Count()); Assert.AreEqual(DateTime.Parse("2/19/1942"), resultBirthdate.First().DateOfBirth); Assert.AreEqual(DateTime.Parse("12/1/2001"), resultBirthdate.Last().DateOfBirth); }
public void Get_Records_Sucsess() { // Arrange Mock <IHistoryRecordService> mock = new Mock <IHistoryRecordService>(); mock.Setup(m => m.GetHistoryRecords()).Returns(historyRecords); var historyRecordService = mock.Object; var controller = new RecordsController(historyRecordService); AutoMapperConfiguration.Configure(); // Act IEnumerable <HistoryRecordViewModel> result = controller.Get(); // Assert Assert.IsNotNull(result); Assert.AreEqual(2, result.Count()); }
public async void GetByIdReturnsNotFoundWhenNoMatchExists() { Models.Record record = null; var mockRecordRepository = new Mock <IRecordRepository>(); mockRecordRepository .Setup(p => p.Get("2")) .Returns(async() => { await Task.Yield(); return(record); }); var recordRepository = mockRecordRepository.Object; var target = new RecordsController(recordRepository); var result = await target.Get("2"); Assert.IsAssignableFrom <HttpNotFoundResult>(result); }
public void Get_Url_Sucsess() { // Arrange Mock <IHistoryRecordService> mock = new Mock <IHistoryRecordService>(); mock.Setup(m => m.GetHistoryRecord(It.IsAny <long>())).Returns(historyRecords[1]); var historyRecordService = mock.Object; var controller = new RecordsController(historyRecordService); SetupControllerForTests(controller); string hash = "70y856ilox"; // Act RedirectResult result = (RedirectResult)controller.Get(hash); // Assert //Assert.AreEqual(System.Net.HttpStatusCode.Moved, result.StatusCode); Assert.AreEqual("https://fake/page/1", result.Location.AbsoluteUri); }
public async void GetAllReturnsNoResultsWhenRepositoryReturnsNull() { Models.Record[] records = null; var mockRecordRepository = new Mock <IRecordRepository>(); mockRecordRepository .Setup(p => p.GetAll()) .Returns(async() => { await Task.Yield(); return(records); }); var recordRepository = mockRecordRepository.Object; var target = new RecordsController(recordRepository); var result = await target.Get(); Assert.IsAssignableFrom <ObjectResult>(result); var expected = JsonConvert.SerializeObject(new { items = new Models.Record[] { } }); Assert.Equal(expected, JsonConvert.SerializeObject(((ObjectResult)result).Value)); }
public void Post() { // Arrange RecordsController controller = new RecordsController(); RecordsController.pdir.Plist = new List <ClassLibrary.PersonInfo>(); // Act string value = "fox, kelly, female, brown, 8/5/1992"; controller.Post(value); List <string> result = controller.Get("gender").ToList(); bool match = true; if (result.Count != 1 || result[0] != value) { match = false; } // Assert Assert.AreEqual(true, match); }
public void Get_Ok() { // Arrange var expectedCreatedDate = DateTime.UtcNow; var expectedModifiedDate = DateTime.UtcNow.AddMinutes(1); var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <Model.Record, Model.Contracts.RecordContract>(); }); var mapper = configuration.CreateMapper(); var repo = Substitute.For <IRepository>(); repo.FindRecord(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()) .Returns(new Model.Record { ApplicationName = "Unit Tests", DataType = "Test Result", DateCreated = expectedCreatedDate, DateModified = expectedModifiedDate, Version = "1.0", Value = "Pass" }); var logger = Substitute.For <ILogger <RecordsController> >(); var target = new RecordsController(repo, logger, mapper); // Act var result = target.Get("testAppName", "dataType", "version1").Result; // Assert Assert.IsType <OkObjectResult>(result); Assert.Equal("Pass", ((Model.Contracts.RecordContract)((OkObjectResult)result).Value).Value); Assert.Equal(expectedCreatedDate, ((Model.Contracts.RecordContract)((OkObjectResult)result).Value).DateCreated); Assert.Equal(expectedModifiedDate, ((Model.Contracts.RecordContract)((OkObjectResult)result).Value).DateModified); }
public void Get_Throws() { // Arrange var mapper = Substitute.For <IMapper>(); var repo = Substitute.For <IRepository>(); repo.FindRecord(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()).Returns(Task.FromException <Model.Record>(new System.Exception("Boom"))); var logger = Substitute.For <ILogger <RecordsController> >(); var target = new RecordsController(repo, logger, mapper); // Act var result = target.Get("testAppName", "dataType", "version1").Result; // Assert logger.Received().Log( LogLevel.Error, Arg.Any <EventId>(), Arg.Is <object>(o => o.ToString() == "Boom"), null, Arg.Any <Func <object, Exception, string> >()); Assert.IsType <BadRequestObjectResult>(result); }
public async void GetByIdReturnsMatch() { var record = new Models.Record { Id = "1", Value = "Value 1" }; var recordRepositoryMock = new Mock <IRecordRepository>(); recordRepositoryMock .Setup(p => p.Get(It.Is <string>(s => s == "1"))) .Returns(async() => { await Task.Yield(); return(record); }); var recordRepository = recordRepositoryMock.Object; var target = new RecordsController(recordRepository); var result = await target.Get("1"); Assert.IsAssignableFrom <ObjectResult>(result); var expected = JsonConvert.SerializeObject(record); Assert.Equal(expected, JsonConvert.SerializeObject(((ObjectResult)result).Value)); }
public void TestGetAll() { int numberofrecords = _recordController.Get().Count(); Assert.AreEqual(numberofrecords, _recordController.Get().Count()); }
public void TestGet() { Record testRecord = recordsController.Get(1); Assert.IsNotNull(testRecord); }
public static void Test_that_ordering_is_correct( ) { var randomProvider = new Random( ); var person1 = PreferencesHelpers.GenerateRandomRecord(randomProvider); var person1A = new PersonColorPreferenceModel( ).PopulateFrom(person1); person1A.LastName = "person1A"; var person2 = PreferencesHelpers.GenerateRandomRecord(randomProvider); var person3 = PreferencesHelpers.GenerateRandomRecord(randomProvider); var person3A = new PersonColorPreferenceModel( ).PopulateFrom(person3); person3A.LastName = "person3A"; var newRecords = new List <PersonColorPreferenceModel> { person1, PreferencesHelpers.GenerateRandomRecord(randomProvider), person1, PreferencesHelpers.GenerateRandomRecord(randomProvider), person2, PreferencesHelpers.GenerateRandomRecord(randomProvider), person2, PreferencesHelpers.GenerateRandomRecord(randomProvider), PreferencesHelpers.GenerateRandomRecord(randomProvider), person3, PreferencesHelpers.GenerateRandomRecord(randomProvider), person3 }.ToSafeList( ); var target = new RecordsController( ); var model = RecordsApiModel.CurrentModel; newRecords.ForEach(newRecord => target.PostLine(UnitTestHelpers.GenerateLine(newRecord, '|'))); model.Add(newRecords); var added = model.PersonColorPreferences.ToSafeList( ); var byBirthDate = target.Birthdate( ).ToSafeList( ); var byGenderLastName = target.Gender( ).ToSafeList( ); var byLastNameDescending = target.LastName( ).ToSafeList( ); var byName = target.Name( ).ToSafeList( ); var byGet = target.Get( ).ToSafeList( ); added.Aggregate((arg1, arg2) => { Assert.True(arg1.Id < arg2.Id); return(arg2); }); byGet.Aggregate((arg1, arg2) => { Assert.True(arg1.Id < arg2.Id); return(arg2); }); byBirthDate.Aggregate((arg1, arg2) => { Assert.True(arg1.DateTimeBirth <= arg2.DateTimeBirth); return(arg2); }); byGenderLastName.Aggregate((arg1, arg2) => { var order = string.Compare(arg1.Gender, arg2.Gender, StringComparison.InvariantCulture); Assert.True(order <= 0); if (order == 0) { var order2 = string.Compare(arg1.LastNameUpper, arg2.LastNameUpper, StringComparison.InvariantCulture); Assert.True(order2 <= 0); } return(arg2); }); byLastNameDescending.Aggregate((arg1, arg2) => { Assert.True(string.Compare(arg1.LastNameUpper, arg2.LastNameUpper, StringComparison.InvariantCulture) >= 0); return(arg2); }); byName.Aggregate((arg1, arg2) => { var order = string.Compare(arg1.LastNameUpper, arg2.LastNameUpper, StringComparison.InvariantCulture); Assert.True(order <= 0); if (order == 0) { var order2 = string.Compare(arg1.FirstNameUpper, arg2.FirstNameUpper, StringComparison.InvariantCulture); Assert.True(order2 <= 0); } return(arg2); }); }
public void testGetone() { Record records = con.Get("Wow"); Assert.AreEqual(records.Title, "Wow"); }