public void CheckThatTheCatListOnlyContiansCats() { var ownerWithCat = new Owner(); ownerWithCat.Pets.Add(new Pet { Name = "Tigger", Type = "Cat" }); var ownerWithOutCat = new Owner(); ownerWithOutCat.Pets.Add(new Pet { Name = "Arnold", Type = "Aardvark" }); var listOfOwners = new List <Owner> { ownerWithCat, ownerWithOutCat }; var owners = new Owners(); owners.Initialise(listOfOwners); Assert.AreEqual(2, owners.PetOwners.Count); Assert.AreEqual(1, owners.CatOwners.Count()); }
public void OnGetWithOwnerNameNoMatch() { var repository = Substitute.For <IOwnerRepository>(); var owners = new Owners(); owners.Initialise(new List <DomainModel.Owner> { new DomainModel.Owner { Name = "John" } }); repository.GetAllOwners().Returns(owners); var indexModel = new IndexModel(repository); Assert.IsNotNull(indexModel); indexModel.OnGet("Fred"); Assert.IsNull(indexModel.Owner); Assert.IsNull(indexModel.Owners); Assert.AreEqual("Fred not found?", indexModel.Message); repository.Received(1).GetAllOwners(); }
public void OnGet() { var repository = Substitute.For <IOwnerRepository>(); var owners = new Owners(); owners.Initialise(new List <DomainModel.Owner> { new DomainModel.Owner { Name = "John" } }); repository.GetAllOwners().Returns(owners); var indexModel = new IndexModel(repository); Assert.IsNotNull(indexModel); indexModel.OnGet(string.Empty); Assert.IsNull(indexModel.Owner); Assert.IsNotNull(indexModel.Owners); Assert.AreEqual(1, indexModel.Owners.Count); Assert.AreEqual(string.Empty, indexModel.Message); repository.Received(1).GetAllOwners(); }
/// <summary> /// Provide access to all owners. /// </summary> /// <returns>A <see cref="Owners"/> <see langword="object"/>.</returns> public Owners GetAllOwners() { var owners = new Owners(); if (!_memoryCache.TryGetValue(EndpointURL, out List <Owner> listOfOwners)) { var task = HttpClient.GetAsync(EndpointURL) .ContinueWith(taskwithresponse => { var response = taskwithresponse.Result; if (response.StatusCode == HttpStatusCode.OK) { var jsonString = response.Content.ReadAsStringAsync(); jsonString.Wait(); listOfOwners = ValidateAndParseResponse(jsonString.Result); } }); task.Wait(); _memoryCache.Set(EndpointURL, listOfOwners, TimeSpan.FromMinutes(60)); } owners.Initialise(listOfOwners); return(owners); }