public override Type BindToType(string assemblyName, string typeName)
        {
            var versionedTypeName    = VersionedTypeName.Parse(typeName);
            var originalTypeFullName = $"{versionedTypeName.OriginalName}, {assemblyName}";
            var originalType         = Type.GetType(originalTypeFullName, false);

            if (originalType == null)
            {
                throw new CantFindTypeException(originalTypeFullName);
            }

            int typeMaxVersion = 0;

            if (!_typeMaxVersions.TryGetValue(originalType, out typeMaxVersion))
            {
                throw new CantFindTypeLatestVersionException(originalType);
            }

            //if max version is reached, should return type without version number
            //because it is most recent version used in code now
            if (typeMaxVersion == versionedTypeName.Version)
            {
                return(originalType);
            }

            //otherwise return original type, as it acts like "history"
            originalTypeFullName = $"{typeName}, {assemblyName}";
            return(Type.GetType(originalTypeFullName));
        }
        public void Original_version_is_resolved_with_default_version()
        {
            var versionedType = VersionedTypeName.Parse(typeof(TestType), 10);

            Assert.AreEqual(typeof(TestType).Name, versionedType.OriginalName);
            Assert.AreEqual(10, versionedType.Version);
        }
Beispiel #3
0
        public void Given_historical_event_it_writes_version_from_type_name()
        {
            var evt = new TestEvent_V1(Guid.NewGuid());
            var serializedString = SerializedToString(evt);

            var expectedTypeName = VersionedTypeName.Parse(typeof(TestEvent_V1)).ToString();

            Assert.True(serializedString.Contains(expectedTypeName));
        }
Beispiel #4
0
        public void Given_original_event_it_writes_its_version_in_type_name()
        {
            var evt = new TestEvent(Guid.NewGuid().ToString());
            var serializedString = SerializedToString(evt);

            var expectedTypeName = VersionedTypeName.Parse(typeof(TestEvent), 2).ToString();

            Assert.Contains(expectedTypeName, serializedString);
        }
        public void Given_history_type_version_is_taken_from_type_name()
        {
            var versionedType = VersionedTypeName.Parse(typeof(TestType_V1));

            Assert.AreEqual(1, versionedType.Version);
        }
 public void Given_bad_exeption_is_raised()
 {
     Assert.Throws <VersionedTypeParseExeption>(() => VersionedTypeName.Parse(typeof(BadNamedType_V1_V1)));
 }