public void TruncateSubfolderNameAndFileNamesButNotSubfolderInfo() { var formatter = Substitute.For <PathFormatter>(); formatter.FolderExists(Arg.Any <string>()).Returns(false); formatter.MaxPathLength = 70; const string folder = @"C:\lorem\ipsum\"; // 15 znakov const string fileName = "too long filename.txt"; // 17 znakov názov súboru, 4 znaky prípona = 21 znakov const string subfolderInfo = "sfinfo"; // 6 znakov, ale vo výsledku bude 7 - medzera // Nnajdlhšie info má 10 znakov vo výslednej ceste však dokopy 13 - zátvorky a medzera. var fileInfos = new Dictionary <int, string>() { { 1, "info 1" }, { 2, "info 22" }, { 3, "info 333" }, { 4, "info 4444" }, { 5, "info 55555" } }; // Výsledná dĺžka cesty najdlhšieho súboru by bola 15 + 18 + 7 + 21 + 13 = 74 znakov. // 18 = podadresár ktorý vznikne z názvu súboru "too long filename" + lomítko. // Limit je 70, preto musím cestu skrátiť o 4 znaky. // Číslo sa rozdelí na polovicu (v tomto prípade 2) a o tento počet sa skracuje aj podadresár aj názov súboru. var expected = new Dictionary <int, string>() { { 1, @"C:\lorem\ipsum\too long filena sfinfo\too long filena (info 1).txt" }, { 2, @"C:\lorem\ipsum\too long filena sfinfo\too long filena (info 22).txt" }, { 3, @"C:\lorem\ipsum\too long filena sfinfo\too long filena (info 333).txt" }, { 4, @"C:\lorem\ipsum\too long filena sfinfo\too long filena (info 4444).txt" }, { 5, @"C:\lorem\ipsum\too long filena sfinfo\too long filena (info 55555).txt" } }; var actual = formatter.FormatPathsInSubfolder(folder, fileName, subfolderInfo, fileInfos); var comparer = new GenericDictionaryAssertions <int, string>(actual); comparer.Equal(expected); }
public static void EntityShouldBeEquivalentTo(this GenericDictionaryAssertions <string, object> assertions, InvalidRecord record) { record.Should().NotBeNull(); var expected = new Dictionary <string, object>() { { "_id", record.Id }, { "Type", record.RecordType.ToString() }, { "FileId", record.ParentId }, { "OwnedBy", record.OwnedBy }, { "CreatedBy", record.CreatedBy }, { "CreatedDateTime", record.CreatedDateTime.UtcDateTime }, { "UpdatedBy", record.UpdatedBy }, { "UpdatedDateTime", record.UpdatedDateTime.UtcDateTime }, { "Index", record.Index }, { "Status", record.Status.ToString() }, { "Message", record.Error }, { "Version", record.Version } }; assertions.Subject.ShouldAllBeEquivalentTo(expected); }
public static void TabularEntityShouldBeEquivalentTo(this GenericDictionaryAssertions <string, object> assertions, TabularFile file) { var expected = new Dictionary <string, object>() { { "_id", file.Id }, { "Blob", new Dictionary <string, object>() { { "_id", file.BlobId }, { "Bucket", file.Bucket }, { "Length", file.Length }, { "Md5", file.Md5 } } }, { "SubType", FileType.Tabular.ToString() }, { "OwnedBy", file.OwnedBy }, { "CreatedBy", file.CreatedBy }, { "CreatedDateTime", file.CreatedDateTime.UtcDateTime }, { "UpdatedBy", file.UpdatedBy }, { "UpdatedDateTime", file.UpdatedDateTime.UtcDateTime }, { "ParentId", file.ParentId }, { "Name", file.FileName }, { "Status", file.Status.ToString() }, { "Version", file.Version } }; if (file.Images.Any()) { expected.Add("Images", file.Images.Select(i => new Dictionary <string, object> { { "_id", i.Id }, { "Height", i.Height }, { "Width", i.Height }, { "MimeType", i.MimeType }, { "Scale", i.GetScale() }, { "Bucket", i.Bucket } })); } assertions.Subject.Should().BeEquivalentTo(expected); }
public static void EntityShouldBeEquivalentTo(this GenericDictionaryAssertions <string, object> assertions, MicroscopyFile file) { assertions.Subject.Should().BeEquivalentTo(new Dictionary <string, object> { { "_id", file.Id }, { "Blob", new Dictionary <string, object>() { { "_id", file.BlobId }, { "Bucket", file.Bucket }, { "Length", file.Length }, { "Md5", file.Md5 } } }, { "SubType", FileType.Microscopy.ToString() }, { "OwnedBy", file.OwnedBy }, { "CreatedBy", file.CreatedBy }, { "CreatedDateTime", file.CreatedDateTime.UtcDateTime }, { "UpdatedBy", file.UpdatedBy }, { "UpdatedDateTime", file.UpdatedDateTime.UtcDateTime }, { "ParentId", file.ParentId }, { "Name", file.FileName }, { "Status", file.Status.ToString() }, { "Version", file.Version }, { "Images", file.Images.Select(i => new Dictionary <string, object> { { "_id", i.Id }, { "Bucket", file.Bucket }, { "Height", i.Height }, { "Width", i.Height }, { "MimeType", i.MimeType }, { "Scale", i.GetScale() } }) }, { "Properties", new Dictionary <string, object>() { { "BioMetadata", file.BioMetadata.Select(i => new Dictionary <string, object> { { "Name", i.Name }, { "Value", i.Value } }) } } } }); }
public static void ModelNodeShouldBeEquivalentTo(this GenericDictionaryAssertions <string, object> assertions, Model model) { var expected = new Dictionary <string, object>() { { "_id", model.Id }, { "Type", "Model" }, { "Blob", new Dictionary <string, object>() { { "_id", model.BlobId }, { "Bucket", model.Bucket } } }, { "Status", model.Status.ToString() }, { "OwnedBy", model.OwnedBy }, { "CreatedBy", model.CreatedBy }, { "CreatedDateTime", model.CreatedDateTime.UtcDateTime }, { "UpdatedBy", model.UpdatedBy }, { "UpdatedDateTime", model.UpdatedDateTime.UtcDateTime }, { "Name", model.Name }, { "ParentId", model.ParentId }, { "Version", model.Version } }; if (model.Images.Any()) { expected.Add("Images", model.Images.Select(i => new Dictionary <string, object> { { "_id", i.Id }, { "Height", i.Height }, { "Width", i.Height }, { "MimeType", i.MimeType }, { "Scale", i.GetScale() }, { "Bucket", i.Bucket } })); } assertions.Subject.ShouldAllBeEquivalentTo(expected); }
public void FormatPathsInNonExistingSubfolderWithSubfolderInfo() { int counter = 0; var formatter = Substitute.For <PathFormatter>(); formatter.FolderExists(Arg.Any <string>()).Returns( (x) => { counter += 1; return(counter < 5); }); const string folder = @"C:\lorem\ipsum"; const string SubfolderInfo = "some info"; const string fileName = "file.txt"; var fileInfos = new Dictionary <int, string>() { { 1, "info 1" }, { 2, "info 2" }, { 3, "info 3" }, { 4, "info 4" } }; var expected = new Dictionary <int, string>() { { 1, @"C:\lorem\ipsum\file some info (4)\file (info 1).txt" }, { 2, @"C:\lorem\ipsum\file some info (4)\file (info 2).txt" }, { 3, @"C:\lorem\ipsum\file some info (4)\file (info 3).txt" }, { 4, @"C:\lorem\ipsum\file some info (4)\file (info 4).txt" } }; var actual = formatter.FormatPathsInSubfolder(folder, fileName, SubfolderInfo, fileInfos); var comparer = new GenericDictionaryAssertions <int, string>(actual); comparer.Equal(expected); }
public void TruncatePathsWithoutSubfolderWhenPathIsTooLong() { var formatter = Substitute.For <PathFormatter>(); formatter.FolderExists(Arg.Any <string>()).Returns(true); formatter.MaxPathLength = 40; const string folder = @"C:\lorem\ipsum\"; // 15 znakov const string fileName = "too long filename.txt"; // 17 znakov názov súboru, 4 znaky prípona = 21 znakov // Nnajdlhšie info má 10 znakov vo výslednej ceste však dokopy 13 - zátvorky a medzera. var fileInfos = new Dictionary <int, string>() { { 1, "info 1" }, { 2, "info 22" }, { 3, "info 333" }, { 4, "info 4444" }, { 5, "info 55555" } }; // Výsledná dĺžka cesty najdlhšieho súboru by bola 15 + 21 + 13 = 49 znakov. // Limit je 40, preto musím cestu skrátiť o 9 znakov. var expected = new Dictionary <int, string>() { { 1, @"C:\lorem\ipsum\too long (info 1).txt" }, { 2, @"C:\lorem\ipsum\too long (info 22).txt" }, { 3, @"C:\lorem\ipsum\too long (info 333).txt" }, { 4, @"C:\lorem\ipsum\too long (info 4444).txt" }, { 5, @"C:\lorem\ipsum\too long (info 55555).txt" } }; var actual = formatter.FormatPaths(folder, fileName, fileInfos); var comparer = new GenericDictionaryAssertions <int, string>(actual); comparer.Equal(expected); }
public static void HaveKey <TKey, TValue>(this GenericDictionaryAssertions <TKey, TValue> dictAssertions, TKey key, string because = "") { dictAssertions.Subject.ContainsKey(key).Should().BeTrue(because); }
public static void ModelEntityShouldBeEquivalentTo(this GenericDictionaryAssertions <string, object> assertions, Model model) { var expected = new Dictionary <string, object> { { "_id", model.Id }, { "OwnedBy", model.OwnedBy }, { "CreatedBy", model.CreatedBy }, { "CreatedDateTime", model.CreatedDateTime.UtcDateTime }, { "KFold", model.KFold }, { "TestDatasetSize", model.TestDatasetSize }, { "SubSampleSize", model.SubSampleSize }, { "ClassName", model.ClassName }, { "Fingerprints", model.Fingerprints.Select(f => new Dictionary <string, object> { { "Type", f.Type }, { "Size", f.Size }, { "Radius", f.Radius } }) }, { "UpdatedBy", model.UpdatedBy }, { "UpdatedDateTime", model.UpdatedDateTime.UtcDateTime }, { "ParentId", model.ParentId }, { "Status", model.Status.ToString() }, { "Method", model.Method.ToString() }, { "Scaler", model.Scaler }, { "Version", model.Version }, { "Blob", new Dictionary <string, object>() { { "_id", model.BlobId }, { "Bucket", model.Bucket } } }, { "Name", model.Name }, { "DisplayMethodName", model.DisplayMethodName } }; if (model.Modi != 0) { expected.Add("Modi", model.Modi); } if (model.Dataset != null) { expected.Add("Dataset", new Dictionary <string, object>() { { "BlobId", model.Dataset.BlobId }, { "Bucket", model.Dataset.Bucket }, { "Title", model.Dataset.Title }, { "Description", model.Dataset.Description } }); } if (model.Property != null) { expected.Add("Property", new Dictionary <string, object>() { { "Category", model.Property.Category }, { "Description", model.Property.Description }, { "Name", model.Property.Name }, { "Units", model.Property.Units } }); } if (model.Images.Any()) { expected.Add("Images", model.Images.Select(i => new Dictionary <string, object> { { "_id", i.Id }, { "Height", i.Height }, { "Width", i.Height }, { "MimeType", i.MimeType }, { "Scale", i.GetScale() }, { "Bucket", i.Bucket } })); } if (model.Metadata != null) { var jsonMeta = JsonConvert.SerializeObject(model.Metadata); var modelMetaBson = BsonSerializer.Deserialize <Dictionary <string, object> >(jsonMeta); expected.Add("Metadata", modelMetaBson); } Log.Information($"Expected: {JsonConvert.SerializeObject(expected)}"); Log.Information($"Subject: {JsonConvert.SerializeObject(assertions.Subject)}"); expected.ShouldAllBeEquivalentTo(assertions.Subject); //assertions.Subject.ShouldAllBeEquivalentTo(expected); }
public static void EntityShouldBeEquivalentTo(this GenericDictionaryAssertions <string, object> assertions, Record record) { record.Should().NotBeNull(); var expected = new Dictionary <string, object>() { { "_id", record.Id }, { "Type", record.RecordType.ToString() }, { "Name", record.Index.ToString() }, { "FileId", record.ParentId }, { "Blob", new Dictionary <string, object>() { { "_id", record.BlobId }, { "Bucket", record.Bucket }, } }, { "OwnedBy", record.OwnedBy }, { "CreatedBy", record.CreatedBy }, { "CreatedDateTime", record.CreatedDateTime.UtcDateTime }, { "UpdatedBy", record.UpdatedBy }, { "UpdatedDateTime", record.UpdatedDateTime.UtcDateTime }, { "Index", record.Index }, { "Properties", new Dictionary <string, object> { { "Fields", record.Fields.Select(f => new Dictionary <string, object> { { "Name", f.Name }, { "Value", f.Value } }) } } }, { "Status", record.Status.ToString() }, { "Version", record.Version } }; if (record.Images.Any()) { expected.Add("Images", record.Images.Select(i => new Dictionary <string, object> { { "_id", i.Id }, { "Bucket", i.Bucket }, { "Format", i.Format }, { "Height", i.Height }, { "Width", i.Height }, { "MimeType", i.MimeType }, { "Exception", i.Exception } })); } if (record is Substance) { (expected["Properties"] as IDictionary <string, object>)["ChemicalProperties"] = record.Properties.Select(p => new Dictionary <string, object> { { "Name", p.Name }, { "Value", p.Value }, { "Error", p.Error } }); if (record.Issues.Any()) { (expected["Properties"] as IDictionary <string, object>)["Issues"] = record.Issues.Select(p => new Dictionary <string, object> { { "Code", p.Code }, { "AuxInfo", p.AuxInfo }, { "Message", p.Message }, { "Severity", p.Severity.ToString() }, { "Title", p.Title } }); } } assertions.Subject.Should().BeEquivalentTo(expected); }
public WhichValueConstraint(GenericDictionaryAssertions <TKey, TValue> parentConstraint, TValue value) : base(parentConstraint) { WhichValue = value; }