public void Test_UnionTypeValidation() { var type = new StonUnionType(new IStonType[] { }); try { Helpers.Validator.ValidateType(type); Assert.Fail("no type:\n The type is valid. This should *not* have happened."); } catch (StonException ex) { Assert.AreEqual(ex.Message, "A union type must have at least two permitted types."); } type = new StonUnionType(new IStonType[] { new StonNamedType("type") }); try { Helpers.Validator.ValidateType(type); Assert.Fail("one type:\n The type is valid. This should *not* have happened."); } catch (StonException ex) { Assert.AreEqual(ex.Message, "A union type must have at least two permitted types."); } type = new StonUnionType(new IStonType[] { new StonNamedType("type"), new StonNamedType("other type") }); try { Helpers.Validator.ValidateType(type); } catch (StonException ex) { Assert.Fail(ex.Message); } }
public void Test_ArgumentNull() { // things would have been a great deal easier if the non-nullable reference type was implemented already... AggregateTester.New() // STON elements construction .Add("new StonSimpleEntity.Copy(value)", () => ExpectArgumentNull(() => new StonSimpleEntity(null as IStonSimpleValue), "value")) .Add("new StonReferenceEntity(address,globalIdentifier)", () => ExpectArgumentNull(() => new StonReferenceEntity(null as IStonAddress), "address")) .Add("new StonNamedType.Copy(name,typeParameters,isExtension)", () => ExpectArgumentNull(() => new StonNamedType(null as string), "name")) .Add("new StonCollectionType.Copy(elementType)", () => ExpectArgumentNull(() => new StonCollectionType(null as IStonType), "elementType")) .Add("new StonUnionType(permittedTypes)", () => ExpectArgumentNull(() => new StonUnionType(null as IEnumerable <IStonType>), "permittedTypes")) .Add("new StonSimpleValue(value)", () => ExpectArgumentNull(() => StonSimpleValue.Copy(null), "value")) .Add("new StonBindingName(name,isExtension)", () => ExpectArgumentNull(() => new StonBindingName(null as string), "name")) .Add("new StonBindingIndex(bindingIndex)", () => ExpectArgumentNull(() => new StonBindingIndex(null as IEnumerable <IStonEntity>), "parameters")) .Add("new StonAddress(initialContext,relativePath)", () => ExpectArgumentNull(() => new StonAddress(null, null), "initialContext")) .Add("new StonGlobalEntityInitialContext(globalIdentifier)", () => ExpectArgumentNull(() => new StonGlobalEntityInitialContext(null as string), "globalIdentifier")) .Add("new StonMemberPathSegment(bindingKey)", () => ExpectArgumentNull(() => new StonMemberPathSegment(null as IStonBindingKey), "bindingKey")) .Add("new StonCollectionElementPathSegment(bindingKey)", () => ExpectArgumentNull(() => new StonCollectionElementPathSegment(null as IStonEntity), "elementIndex")) // STON elements copying .Add("StonEntity.Copy(entity)", () => ExpectArgumentNull(() => StonEntity.Copy(null), "entity")) .Add("StonValuedEntity.Copy(entity)", () => ExpectArgumentNull(() => StonValuedEntity.Copy(null), "entity")) .Add("StonSimpleEntity.Copy(entity)", () => ExpectArgumentNull(() => StonSimpleEntity.Copy(null), "entity")) .Add("StonComplexEntity.Copy(entity)", () => ExpectArgumentNull(() => StonComplexEntity.Copy(null), "entity")) .Add("StonReferenceEntity.Copy(entity)", () => ExpectArgumentNull(() => StonReferenceEntity.Copy(null), "entity")) .Add("StonType.Copy(type)", () => ExpectArgumentNull(() => StonType.Copy(null), "type")) .Add("StonNamedType.Copy(type)", () => ExpectArgumentNull(() => StonNamedType.Copy(null), "type")) .Add("StonCollectionType.Copy(type)", () => ExpectArgumentNull(() => StonCollectionType.Copy(null), "type")) .Add("StonUnionType.Copy(type)", () => ExpectArgumentNull(() => StonUnionType.Copy(null), "type")) .Add("StonSimpleValue.Copy(value)", () => ExpectArgumentNull(() => StonSimpleValue.Copy(null), "value")) .Add("StonConstruction.Copy(construction)", () => ExpectArgumentNull(() => StonConstruction.Copy(null), "construction")) .Add("StonMemberInit.Copy(memberInit)", () => ExpectArgumentNull(() => StonMemberInit.Copy(null), "memberInit")) .Add("StonBindingKey.Copy(bindingKey)", () => ExpectArgumentNull(() => StonBindingKey.Copy(null), "bindingKey")) .Add("StonBindingName.Copy(bindingName)", () => ExpectArgumentNull(() => StonBindingName.Copy(null), "bindingName")) .Add("StonBindingIndex.Copy(bindingIndex)", () => ExpectArgumentNull(() => StonBindingIndex.Copy(null), "bindingIndex")) .Add("StonCollectionInit.Copy(collectionInit)", () => ExpectArgumentNull(() => StonCollectionInit.Copy(null), "collectionInit")) .Add("StonAddress.Copy(address)", () => ExpectArgumentNull(() => StonAddress.Copy(null), "address")) .Add("StonInitialContext.Copy(context)", () => ExpectArgumentNull(() => StonInitialContext.Copy(null), "context")) .Add("StonAncestorInitialContext.Copy(context)", () => ExpectArgumentNull(() => StonAncestorInitialContext.Copy(null), "context")) .Add("StonGlobalEntityInitialContext.Copy(context)", () => ExpectArgumentNull(() => StonGlobalEntityInitialContext.Copy(null), "context")) .Add("StonPathSegment.Copy(segment)", () => ExpectArgumentNull(() => StonPathSegment.Copy(null), "segment")) .Add("StonAncestorPathSegment.Copy(segment)", () => ExpectArgumentNull(() => StonAncestorPathSegment.Copy(null), "segment")) .Add("StonMemberPathSegment.Copy(segment)", () => ExpectArgumentNull(() => StonMemberPathSegment.Copy(null), "segment")) .Add("StonCollectionElementPathSegment.Copy(segment)", () => ExpectArgumentNull(() => StonCollectionElementPathSegment.Copy(null), "segment")) // document methods .Add("StonDocument.GetParentContext(context)", () => ExpectArgumentNull <IStonDocument>((document) => document.GetParentContext(null), "context")) .Add("StonDocument.GetMember(entity?,memberKey)", () => ExpectArgumentNull <IStonDocument>((document) => document.GetMember(null, null), "entity")) .Add("StonDocument.GetMember(entity,memberKey?)", () => ExpectArgumentNull <IStonDocument>((document) => document.GetMember(document.Core as IStonComplexEntity, null), "memberKey")) .Add("StonDocument.GetReferencedValue(reference)", () => ExpectArgumentNull <IStonDocument>((document) => document.GetReferencedValue(null), "reference")) // reading/writing .Add("new StonReader(elementFactory?,documentFactory)", () => ExpectArgumentNull(() => new RegularStonReader(null, null), "elementFactory")) .Add("new StonReader(elementFactory,documentFactory?)", () => ExpectArgumentNull(() => new RegularStonReader(Building.CoreStonElementFactory.Instance, null), "documentFactory")) .Add("StonReader.ReadEntity(reader)", () => ExpectArgumentNull(() => RegularStonReader.Default.ReadEntity(null), "reader")) .Add("StonReader.ReadDocument(reader,...)", () => ExpectArgumentNull(() => RegularStonReader.Default.ReadDocument(null), "reader")) .Add("new StonTokenReader(innerReader)", () => ExpectArgumentNull(() => new StonTokenReader(null), "innerReader")) .Add("*IStonReader.ParseEntity(value)", () => ExpectArgumentNull(() => (RegularStonReader.Default as IStonReader).ParseEntity(null), "value")) .Add("*IStonReader.ParseEntity<>(value)", () => ExpectArgumentNull(() => RegularStonReader.Default.ParseEntity(null), "value")) .Add("*IStonReader.LoadEntity(stream)", () => ExpectArgumentNull(() => (RegularStonReader.Default as IStonReader).LoadEntity(null as Stream), "stream")) .Add("*IStonReader.LoadEntity<>(stream)", () => ExpectArgumentNull(() => RegularStonReader.Default.LoadEntity(null as Stream), "stream")) .Add("*IStonReader.ParseDocument(value)", () => ExpectArgumentNull(() => (RegularStonReader.Default as IStonReader).ParseDocument(null), "value")) .Add("*IStonReader.ParseDocument<>(value)", () => ExpectArgumentNull(() => RegularStonReader.Default.ParseDocument(null), "value")) .Add("*IStonReader.LoadDocument(stream)", () => ExpectArgumentNull(() => (RegularStonReader.Default as IStonReader).LoadDocument(null as Stream), "stream")) .Add("*IStonReader.LoadDocument<>(stream)", () => ExpectArgumentNull(() => RegularStonReader.Default.LoadDocument(null as Stream), "stream")) .Add("new StonTokenWriter(innerWriter)", () => ExpectArgumentNull(() => new StonTokenWriter(null), "innerWriter")) .Add("StonTokenWriter.WriteStringLiteral(content,delimiter)", () => ExpectArgumentNull((StonTokenWriter writer) => writer.WriteStringLiteral(null), "content")) .Add("StonTokenWriter.WriteBinaryLiteral(content,baseId)", () => ExpectArgumentNull((StonTokenWriter writer) => writer.WriteBinaryLiteral(null), "content")) .Add("StonTokenWriter.WriteCanonicalNumberLiteral(content)", () => ExpectArgumentNull((StonTokenWriter writer) => writer.WriteCanonicalNumberLiteral(null), "content")) .Add("StonTokenWriter.WritePlainNumberLiteral(content)", () => ExpectArgumentNull((StonTokenWriter writer) => writer.WritePlainNumberLiteral(null), "content")) .Add("StonTokenWriter.WriteScientificNumberLiteral(content)", () => ExpectArgumentNull((StonTokenWriter writer) => writer.WriteScientificNumberLiteral(null), "content")) .Add("CanonicalStonWriter.WriteEntity(writer?,entity)", () => ExpectArgumentNull(() => CanonicalStonWriter.Instance.WriteEntity(null, null), "writer")) .Add("CanonicalStonWriter.WriteEntity(writer,entity?)", () => ExpectArgumentNull(() => CanonicalStonWriter.Instance.WriteEntity(new System.IO.StringWriter(), null), "entity")) .Add("CanonicalStonWriter.WriteDocument(writer?,document)", () => ExpectArgumentNull(() => CanonicalStonWriter.Instance.WriteDocument(null, null), "writer")) .Add("CanonicalStonWriter.WriteDocument(writer,document?)", () => ExpectArgumentNull(() => CanonicalStonWriter.Instance.WriteDocument(new System.IO.StringWriter(), null), "document")) .Add("*IStonEntity.ToString(writer)", () => ExpectArgumentNull <IStonEntity>((entity) => entity.ToString(null), "writer")) .Add("*IStonEntity.ToString<>(writer)", () => ExpectArgumentNull <IStonEntity>((entity) => entity.ToString(null as IStonWriter <IStonEntity, IStonDocument>), "writer")) .Add("*IStonEntity.Save(stream?,writer)", () => ExpectArgumentNull <IStonEntity>((entity) => entity.Save(null as Stream, CanonicalStonWriter.Instance), "stream")) .Add("*IStonEntity.Save(stream,writer?)", () => ExpectArgumentNull <IStonEntity>((entity) => entity.Save(new MemoryStream(), null), "writer")) .Add("*IStonEntity.Save<>(stream?,writer)", () => ExpectArgumentNull <IStonEntity>((entity) => entity.Save(null as Stream, null as IStonWriter <IStonEntity, IStonDocument>), "stream")) .Add("*IStonEntity.Save<>(stream,writer?)", () => ExpectArgumentNull <IStonEntity>((entity) => entity.Save(new MemoryStream(), null as IStonWriter <IStonEntity, IStonDocument>), "writer")) .Add("*IStonDocument.ToString(writer)", () => ExpectArgumentNull <IStonDocument>((document) => document.ToString(null), "writer")) .Add("*IStonDocument.ToString<>(writer)", () => ExpectArgumentNull <IStonDocument>((document) => document.ToString(null as IStonWriter <IStonEntity, IStonDocument>), "writer")) .Add("*IStonDocument.Save(stream?,writer)", () => ExpectArgumentNull <IStonDocument>((document) => document.Save(null as Stream, null), "stream")) .Add("*IStonDocument.Save(stream,writer?)", () => ExpectArgumentNull <IStonDocument>((document) => document.Save(new MemoryStream(), null), "writer")) .Add("*IStonDocument.Save<>(stream?,writer)", () => ExpectArgumentNull <IStonDocument>((document) => document.Save(null as Stream, null as IStonWriter <IStonEntity, IStonDocument>), "stream")) .Add("*IStonDocument.Save<>(stream,writer?)", () => ExpectArgumentNull <IStonDocument>((document) => document.Save(new MemoryStream(), null as IStonWriter <IStonEntity, IStonDocument>), "writer")) // equivalence comparing .Add("new StonSemanticEntityEquivalenceComparer(document)", () => ExpectArgumentNull(() => new StonSemanticEntityEquivalenceComparer(null), "document")) .Add("new StonBindingKeyEquivalenceComparer(indexParameterComparer)", () => ExpectArgumentNull(() => new StonBindingKeyEquivalenceComparer(null), "indexParameterComparer")) // validation .Add("ValidateEntity(entity) 1", () => ExpectArgumentNull(() => ValidateEntity(null as IStonEntity), "entity")) .Add("ValidateEntity(entity) 2", () => ExpectArgumentNull(() => ValidateEntity(null as IStonValuedEntity), "entity")) .Add("ValidateEntity(entity) 3", () => ExpectArgumentNull(() => ValidateEntity(null as IStonSimpleEntity), "entity")) .Add("ValidateEntity(entity) 4", () => ExpectArgumentNull(() => ValidateEntity(null as IStonComplexEntity), "entity")) .Add("ValidateEntity(entity) 5", () => ExpectArgumentNull(() => ValidateEntity(null as IStonReferenceEntity), "entity")) .Add("ValidateGlobalIdentifier(globalIdentifier)", () => ExpectArgumentNull(() => ValidateGlobalIdentifier(null), "globalIdentifier")) .Add("ValidateType(type) 1", () => ExpectArgumentNull(() => ValidateType(null as IStonType), "type")) .Add("ValidateType(type) 2", () => ExpectArgumentNull(() => ValidateType(null as IStonNamedType), "type")) .Add("ValidateType(type) 3", () => ExpectArgumentNull(() => ValidateType(null as IStonCollectionType), "type")) .Add("ValidateType(type) 4", () => ExpectArgumentNull(() => ValidateType(null as IStonUnionType), "type")) .Add("ValidateSimpleValue(value)", () => ExpectArgumentNull(() => ValidateSimpleValue(null), "value")) .Add("ValidateConstruction(construction)", () => ExpectArgumentNull(() => ValidateConstruction(null), "construction")) .Add("ValidateMemberInit(memberInit)", () => ExpectArgumentNull(() => ValidateMemberInit(null), "memberInit")) .Add("ValidateBindingKey(bindingKey) 1", () => ExpectArgumentNull(() => ValidateBindingKey(null as IStonBindingKey), "bindingKey")) .Add("ValidateBindingKey(bindingKey) 2", () => ExpectArgumentNull(() => ValidateBindingKey(null as IStonBindingName), "bindingKey")) .Add("ValidateBindingKey(bindingKey) 3", () => ExpectArgumentNull(() => ValidateBindingKey(null as IStonBindingIndex), "bindingKey")) .Add("ValidateCollectionInit(collectionInit)", () => ExpectArgumentNull(() => ValidateCollectionInit(null), "collectionInit")) .Add("ValidateAddress(address)", () => ExpectArgumentNull(() => ValidateAddress(null), "address")) .Add("ValidateInitialContext(initialContext) 1", () => ExpectArgumentNull(() => ValidateInitialContext(null as IStonInitialContext), "initialContext")) .Add("ValidateInitialContext(initialContext) 2", () => ExpectArgumentNull(() => ValidateInitialContext(null as IStonAncestorInitialContext), "initialContext")) .Add("ValidateInitialContext(initialContext) 3", () => ExpectArgumentNull(() => ValidateInitialContext(null as IStonGlobalEntityInitialContext), "initialContext")) .Add("ValidatePathSegment(segment) 1", () => ExpectArgumentNull(() => ValidatePathSegment(null as IStonPathSegment), "segment")) .Add("ValidatePathSegment(segment) 2", () => ExpectArgumentNull(() => ValidatePathSegment(null as IStonAncestorPathSegment), "segment")) .Add("ValidatePathSegment(segment) 3", () => ExpectArgumentNull(() => ValidatePathSegment(null as IStonMemberPathSegment), "segment")) .Add("ValidatePathSegment(segment) 4", () => ExpectArgumentNull(() => ValidatePathSegment(null as IStonCollectionElementPathSegment), "segment")) // ironically, exceptions .Add("new StonImplementationException(elementType?,baseInterface,derivedInterfaces)", () => ExpectArgumentNull(() => new StonImplementationException(null, null, null as Type[]), "elementType")) .Add("new StonImplementationException(elementType,baseInterface?,derivedInterfaces)", () => ExpectArgumentNull(() => new StonImplementationException(typeof(object), null, null as Type[]), "baseInterface")) .Add("new StonImplementationException(elementType,baseInterface,derivedInterfaces?)", () => ExpectArgumentNull(() => new StonImplementationException(typeof(object), typeof(object), null as Type[]), "derivedInterfaces")) .Add("new StonDuplicateGlobalEntityException(firstEntity?,secondEntity)", () => ExpectArgumentNull(() => new StonDuplicateGlobalEntityException(null, null), "firstEntity")) .Add("new StonDuplicateGlobalEntityException(firstEntity,secondEntity?)", () => ExpectArgumentNull(() => new StonDuplicateGlobalEntityException(MakeActor <IStonEntity>(), null), "secondEntity")) .Add("new StonDuplicateGlobalEntityException(firstEntity?,secondEntity,message)", () => ExpectArgumentNull(() => new StonDuplicateGlobalEntityException(null, null, ""), "firstEntity")) .Add("new StonDuplicateGlobalEntityException(firstEntity,secondEntity?,message)", () => ExpectArgumentNull(() => new StonDuplicateGlobalEntityException(MakeActor <IStonEntity>(), null, ""), "secondEntity")) .Add("new StonCircularConstructionException(document?,constructionCycle)", () => ExpectArgumentNull(() => new StonCircularConstructionException(null, null), "document")) .Add("new StonCircularConstructionException(document,constructionCycle?)", () => ExpectArgumentNull <IStonDocument>((document) => new StonCircularConstructionException(document, null), "constructionCycle")) .Add("new StonExtensionTypeException(extensionType)", () => ExpectArgumentNull(() => new StonExtensionTypeException(null as IStonNamedType), "extensionType")) .Add("new StonExtensionTypeException(entity)", () => ExpectArgumentNull(() => new StonExtensionTypeException(null as IStonValuedEntity), "entity")) .Add("new StonExtensionTypeException(memberKey)", () => ExpectArgumentNull(() => new StonExtensionMemberException(null), "memberKey")) .Run(); }