public void ReturnTheProperNameForEachCategory() { string rootPath = $"C:\\{string.Empty.GetRandom()}"; var connectionString = new ConnectionStringBuilder("this") .AddFilePath(rootPath) .Build(); var categories = new CategoryCollectionBuilder() .AddRandomCategories(20.GetRandom(5)) .Build(); var fileSystem = new MockFileServiceBuilder() .AddCategories(categories) .Build(rootPath); var target = new ContentRepositoryBuilder() .AddFileService(fileSystem.Object) .UseGenericDirectory() .Build(connectionString); var actual = target.GetCategories(); foreach (var category in categories) { var actualCategory = actual.SingleOrDefault(c => c.Id == category.Id); Assert.Equal(category.Name, actualCategory.Name); } }
public static CategoryCollectionBuilder AddRandomCategories(this CategoryCollectionBuilder builder, Int32 count) { for (Int32 i = 0; i < count; i++) { builder.AddCategory(new CategoryBuilder() .UseRandom() .Build()); } return(builder); }
public static CategoryCollectionBuilder AddRandomCategories(this CategoryCollectionBuilder builder, int count) { for (int i = 0; i < count; i++) { Guid id = Guid.NewGuid(); string name = string.Empty.GetRandom(); string description = $"{id}_{name}"; builder.AddCategory(id, name, description); } return(builder); }
public void ReturnAllCategories() { var categories = new CategoryCollectionBuilder() .AddRandomCategories() .Build(); var fileSystem = new Mock <IFile>(); fileSystem.ConfigureCategories(categories, _rootPath); var target = (null as IContentRepository).Create(fileSystem.Object, _rootPath); var actual = target.GetCategories(); Assert.Equal(categories.Count(), actual.Count()); }
public void LoadACategoryAnywayEvenIfItHasNoDescriptionAttribute() { var categories = new CategoryCollectionBuilder() .AddCategory(Guid.NewGuid(), String.Empty.GetRandom(), string.Empty) .Build(); var fileSystem = new Mock <IFile>(); fileSystem.ConfigureCategories(categories, _rootPath); var target = (null as IContentRepository).Create(fileSystem.Object, _rootPath); var actual = target.GetCategories(); Assert.Single(actual); }
public void SkipACategoryIfItHasWhitespaceForTheNameValue() { var categories = new CategoryCollectionBuilder() .AddCategory(Guid.NewGuid(), " \t ", "Category with just whitespace in the name") .Build(); var fileSystem = new Mock <IFile>(); fileSystem.ConfigureCategories(categories, _rootPath); var target = (null as IContentRepository).Create(fileSystem.Object, _rootPath); var actual = target.GetCategories(); Assert.Empty(actual); }
public void SkipACategoryIfItHasAnEmptyIdValue() { var categories = new CategoryCollectionBuilder() .AddCategory(Guid.Empty, string.Empty.GetRandom(), "Category with empty id") .Build(); var fileSystem = new Mock <IFile>(); fileSystem.ConfigureCategories(categories, _rootPath); var target = (null as IContentRepository).Create(fileSystem.Object, _rootPath); var actual = target.GetCategories(); Assert.Empty(actual); }
public void ReturnTheProperIdForEachCategory() { var categories = new CategoryCollectionBuilder() .AddRandomCategories() .Build(); var fileSystem = new Mock <IFile>(); fileSystem.ConfigureCategories(categories, _rootPath); var target = (null as IContentRepository).Create(fileSystem.Object, _rootPath); var actual = target.GetCategories(); var expectedHash = categories.Select(c => c.Id).AsHash(); var actualHash = actual.Select(c => c.Id).AsHash(); Assert.Equal(expectedHash, actualHash); }
public void ReturnTheProperDescriptionForEachCategory() { var categories = new CategoryCollectionBuilder() .AddRandomCategories() .Build(); var fileSystem = new Mock <IFile>(); fileSystem.ConfigureCategories(categories, _rootPath); var target = (null as IContentRepository).Create(fileSystem.Object, _rootPath); var actual = target.GetCategories(); foreach (var category in categories) { var actualCategory = actual.SingleOrDefault(c => c.Id == category.Id); Assert.Equal(category.Description, actualCategory.Description); } }
public static CategoryCollectionBuilder AddRandomCategories(this CategoryCollectionBuilder builder) { return(builder.AddRandomCategories(10.GetRandom(5))); }