public void ItGetsGroupCategories() { // Arrange const string slug = "unit-test-GroupCategory"; var rawGroupCategory = new ContentfulGroupCategoryBuilder().Slug(slug).Name("name").Build(); var collection = new ContentfulCollection <ContentfulGroupCategory>(); collection.Items = new List <ContentfulGroupCategory> { rawGroupCategory }; var builder = new QueryBuilder <ContentfulGroupCategory>().ContentTypeIs("groupCategory"); _contentfulClient.Setup(o => o.GetEntries(It.Is <QueryBuilder <ContentfulGroupCategory> >(q => q.Build() == builder.Build()), It.IsAny <CancellationToken>())) .ReturnsAsync(collection); _contentfulGroupCategoryFactory.Setup(_ => _.ToModel(rawGroupCategory)) .Returns(new GroupCategory("name", "slug", "icon", "imageUrl")); // Act var response = AsyncTestHelper.Resolve(_repository.GetGroupCategories()); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); }
public void ShouldReturnAListOfAListOfCategories() { // Arrange const string slug = "unit-test-GroupCategory"; var testCategorySlug = "test-category-slug"; var listOfContentfulGroups = SetupMockFactoriesAndGetContentfulGroupsForCollection(testCategorySlug); var collection = new ContentfulCollection <ContentfulGroup>(); collection.Items = listOfContentfulGroups; var rawContentfulGroupCategory = new ContentfulGroupCategoryBuilder().Slug(slug).Build(); var rawGroupCategory = new GroupCategory("name", slug, "icon", "imageUrl"); var builder = new QueryBuilder <ContentfulGroup>().ContentTypeIs("group").Include(1).FieldEquals("fields.mapPosition[near]", Defaults.Groups.StockportLatitude + "," + Defaults.Groups.StockportLongitude + ",10").Build(); _client.Setup(o => o.GetEntries <ContentfulGroup>(It.Is <string>(q => q.Contains(builder)), It.IsAny <CancellationToken>())).ReturnsAsync(collection); _cacheWrapper.Setup(o => o.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "group-categories"), It.IsAny <Func <Task <List <GroupCategory> > > >(), It.Is <int>(s => s == 60))).ReturnsAsync(new List <GroupCategory>() { rawGroupCategory }); var noLatLngBuilder = new QueryBuilder <ContentfulGroup>().ContentTypeIs("group").Include(1).Build(); _client.Setup(o => o.GetEntries <ContentfulGroup>(It.Is <string>(q => q.Contains(noLatLngBuilder)), It.IsAny <CancellationToken>())).ReturnsAsync(collection); // Act var response = AsyncTestHelper.Resolve(_repository.GetGroupResults(new GroupSearch(), slug)); var filteredGroupResults = response.Get <GroupResults>(); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); filteredGroupResults.Categories.Count.Should().Be(1); }
private List <ContentfulGroup> SetupMockFactoriesAndGetContentfulGroupsForCollection(string testCategorySlug) { var contentfulGroupCategory = new ContentfulGroupCategoryBuilder().Slug(testCategorySlug).Build(); var contentfulGroupWithCategory = new ContentfulGroupBuilder().Slug("slug-with-categories").CategoriesReference( new List <ContentfulGroupCategory> { contentfulGroupCategory }).Build(); var contentfulGroupWithoutCategory = new ContentfulGroupBuilder().Slug("slug-without-categories").Build(); var groupCategory = new GroupCategory("name", testCategorySlug, "icon", "imagueUrl"); var groupWithCategory = new GroupBuilder().Slug("slug-with-categories").CategoriesReference( new List <GroupCategory>() { groupCategory }) .Build(); var groupWithoutCategory = new GroupBuilder().Slug("slug-without-categories").Build(); _groupFactory.Setup(o => o.ToModel(contentfulGroupWithCategory)).Returns(groupWithCategory); _groupFactory.Setup(o => o.ToModel(contentfulGroupWithoutCategory)).Returns(groupWithoutCategory); return(new List <ContentfulGroup> { contentfulGroupWithCategory, contentfulGroupWithoutCategory }); }
public void ShouldCreateAGroupCategoryFromAContentfulGroupCategory() { var contentfulShowcase = new ContentfulGroupCategoryBuilder() .Name("category name") .Slug("category-slug") .Image(new Asset { File = new File { Url = "image-url.jpg" }, SystemProperties = new SystemProperties { Type = "Asset" } }) .Icon("icon") .Build(); var contentfulFactory = new GroupCategoryContentfulFactory(); var category = contentfulFactory.ToModel(contentfulShowcase); category.Should().BeOfType <GroupCategory>(); category.Name.Should().Be("category name"); category.Slug.Should().Be("category-slug"); category.Icon.Should().Be("icon"); category.ImageUrl.Should().Be("image-url.jpg"); }