public void TestCreate_WithBuffering()
        {
            PackerUnpackerStreamOptions.AlwaysWrap = true;
            try
            {
                using (var stream = new MemoryStream())
                    using (var unpacker = Unpacker.Create(stream, new PackerUnpackerStreamOptions {
                        OwnsStream = false, WithBuffering = true, BufferSize = 123
                    }, default(UnpackerOptions)))
                    {
                        Assert.That(unpacker, Is.InstanceOf <MessagePackStreamUnpacker>());
                        var streamUnpacker = unpacker as MessagePackStreamUnpacker;
                        Assert.That(streamUnpacker.DebugOwnsStream, Is.False);
#if !SILVERLIGHT
                        Assert.That(streamUnpacker.DebugSource, Is.Not.SameAs(stream));
#if NETSTANDARD1_1 || NETSTANDARD1_3
                        // Avoid type name conflicts between netcoreapp and msgpack
                        Assert.That(streamUnpacker.DebugSource.GetType().FullName, Is.EqualTo("System.IO.BufferedStream"));
                        Assert.That(streamUnpacker.DebugSource.GetType().GetAssembly().FullName, Is.EqualTo(typeof(MessagePackObject).GetAssembly().FullName));
#else // NETSTANDARD1_1 || NETSTANDARD1_3
                        Assert.That(streamUnpacker.DebugSource, Is.InstanceOf <BufferedStream>());
#endif // // NETSTANDARD1_1 || NETSTANDARD1_3
#else
                        Assert.That(streamUnpacker.DebugSource, Is.SameAs(stream));
#endif // !SILVERLIGHT
                    }
            }
            finally
            {
                PackerUnpackerStreamOptions.AlwaysWrap = false;
            }
        }
Beispiel #2
0
        public async Task TestSingleAllocation_Custom_Binary_EnoughSizeAsync(int offset)
        {
            var allocator = new Allocator();
            var buffer    = new byte[34 + offset];

            using (var target = CreatePacker(buffer, offset, allocator.Reallocate))
            {
                Assert.That(target.InitialBufferOffset, Is.EqualTo(offset));

                await target.PackAsync(Enumerable.Range( 0, 32 ).Select( x => ( byte )x ).ToArray());

                var expected = new byte[] { 0xC4, 0x20, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F };
                Assert.That(target.BytesUsed, Is.EqualTo(expected.Length));

                var bytes = target.GetResultBytes();
                Assert.That(bytes.Offset, Is.EqualTo(target.InitialBufferOffset));
                Assert.That(bytes.Count, Is.EqualTo(target.BytesUsed));
                // Returns same array if buffer contains single array and its segment refers entire array.
                Assert.That(target.GetResultBytes().Array, Is.SameAs(bytes.Array));
                // Returns same array if no allocation has been ocurred.
                Assert.That(bytes.Array, Is.SameAs(buffer));

                // Returns same array if no allocation has been ocurred.
                Assert.That(target.GetFinalBuffer(), Is.SameAs(buffer));

                // Only used contents are returned.
                Assert.That(bytes.ToArray(), Is.EqualTo(expected));
            }
            Assert.That(allocator.IsOnlyReallocateCalled(), Is.False);
        }
Beispiel #3
0
        public void ItReturnsTheExistingChampionIfNothingChanged()
        {
            ChampionData championData = new ChampionData
            {
                GameDefinitionId = gameDefinitionId,
                PlayerId         = playerChampionId
            };

            championRepositoryMock.Expect(mock => mock.GetChampionData(gameDefinitionId))
            .Return(championData);

            List <Champion> championList     = new List <Champion>();
            Champion        existingChampion = new Champion
            {
                Id               = previousChampionId,
                PlayerId         = playerChampionId,
                GameDefinitionId = gameDefinitionId,
                GameDefinition   = new GameDefinition {
                    ChampionId = previousChampionId
                }
            };

            championList.Add(existingChampion);
            dataContextMock.Expect(mock => mock.GetQueryable <Champion>())
            .Return(championList.AsQueryable());

            Champion actualChampion = championRecalculator.RecalculateChampion(gameDefinitionId, applicationUser);

            Assert.That(actualChampion, Is.SameAs(existingChampion));
        }
Beispiel #4
0
        public void Nothing()
        {
            var nothing = Maybe.Nothing <object>();

            Assert.That(nothing.Exists, Is.False);
            Assert.Throws(typeof(SqlNullValueException), () => { Console.WriteLine(nothing.Value); });

            Assert.That(Maybe.Of <object>(null), Is.EqualTo(nothing));
            Assert.That(nothing.Equals(null), Is.False);
            Assert.That(nothing, Is.EqualTo(nothing));
            Assert.That(Maybe.Nothing <object>(), Is.EqualTo(nothing));
            Assert.That(Maybe.Nothing <string>(), Is.EqualTo(nothing));
            Assert.That(Maybe.Just("a").ToString(), Is.Not.EqualTo(nothing));
            Assert.True(nothing.Equals(nothing));

            Assert.That(Maybe.Nothing <string>().ToString(), Is.EqualTo("Nothing"));

            Assert.That(Maybe.Nothing <int>().GetHashCode(), Is.EqualTo(Maybe.Of <string>(null).GetHashCode()));

            var alt = new object();

            Assert.That(nothing.GetOrElse(alt), Is.SameAs(alt));

            var called = false;
            var value  = nothing.GetOrElseGet(() =>
            {
                called = true;
                return(alt);
            });

            Assert.That(called, Is.True);
            Assert.That(value, Is.SameAs(alt));
        }
        public void ItReturnsTheExistingChampionIfNothingChanged()
        {
            ChampionData championData = new ChampionData
            {
                GameDefinitionId = _gameDefinitionId,
                PlayerId         = _playerChampionId
            };

            _autoMocker.Get <IChampionRepository>().Expect(mock => mock.GetChampionData(_gameDefinitionId))
            .Return(championData);

            List <Champion> championList     = new List <Champion>();
            Champion        existingChampion = new Champion
            {
                Id               = _previousChampionId,
                PlayerId         = _playerChampionId,
                GameDefinitionId = _gameDefinitionId,
                GameDefinition   = new GameDefinition {
                    ChampionId = _previousChampionId
                }
            };

            championList.Add(existingChampion);
            _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Champion>())
            .Return(championList.AsQueryable());

            Champion actualChampion = _autoMocker.ClassUnderTest.RecalculateChampion(_gameDefinitionId, _applicationUser);

            Assert.That(actualChampion, Is.SameAs(existingChampion));
        }
Beispiel #6
0
        public async Task TestSingleAllocation_Default_String_EnoughSizeAsync(int offset)
        {
            var buffer = new byte[34 + offset];

            using (var target = CreatePacker(buffer, offset, true))
            {
                Assert.That(target.InitialBufferOffset, Is.EqualTo(offset));

                await target.PackAsync(new string( Enumerable.Range(( int )'A', 32).Select(x => ( char )x).ToArray()));

                var expected = new byte[] { 0xD9, 0x20, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60 };
                Assert.That(target.BytesUsed, Is.EqualTo(expected.Length));

                var bytes = target.GetResultBytes();
                Assert.That(bytes.Offset, Is.EqualTo(target.InitialBufferOffset));
                Assert.That(bytes.Count, Is.EqualTo(target.BytesUsed));
                // Returns same array if buffer contains single array and its segment refers entire array.
                Assert.That(target.GetResultBytes().Array, Is.SameAs(bytes.Array));
                // Returns same array if no allocation has been ocurred.
                Assert.That(bytes.Array, Is.SameAs(buffer));

                // Returns same array if no allocation has been ocurred.
                Assert.That(target.GetFinalBuffer(), Is.SameAs(buffer));

                // Only used contents are returned.
                Assert.That(bytes.ToArray(), Is.EqualTo(expected));
            }
        }
Beispiel #7
0
        public void Just()
        {
            var             a     = new object();
            IMaybe <object> justA = Maybe.Just(a);

            Assert.That(justA.Exists, Is.True);
            Assert.That(a, Is.SameAs(justA.Value));

            Assert.That(Maybe.Of(a), Is.EqualTo(justA));
            Assert.That(justA.Equals(null), Is.False);
            Assert.That(Maybe.Just(a), Is.EqualTo(justA));
            Assert.That(Maybe.Just("b"), Is.Not.EqualTo(justA));
            Assert.That(Maybe.Just <object>("b"), Is.Not.EqualTo(justA));
            Assert.That(Maybe.Nothing <string>(), Is.Not.EqualTo(justA));
            Assert.True(justA.Equals(justA));

            Assert.That(Maybe.Just("a").ToString(), Is.EqualTo("Just(a)"));

            Assert.That(justA.GetHashCode(), Is.EqualTo(justA.Value.GetHashCode()));

            Assert.That(justA.GetOrElse(new object()), Is.SameAs(a));

            bool called = false;

            justA.GetOrElseGet(() =>
            {
                called = true;
                return(new object());
            });
            Assert.That(called, Is.False);
        }
Beispiel #8
0
        public async Task TestSingleAllocation_Custom_Scalar_EnoughSizeAsync(int offset)
        {
            var allocator = new Allocator();
            var buffer    = new byte[9 + offset];

            using (var target = CreatePacker(buffer, offset, allocator.Reallocate))
            {
                Assert.That(target.InitialBufferOffset, Is.EqualTo(offset));

                await target.PackAsync(0x123456789AL);

                var expected = new byte[] { 0xD3, 0, 0, 0, 0x12, 0x34, 0x56, 0x78, 0x9A };
                Assert.That(target.BytesUsed, Is.EqualTo(expected.Length));

                var bytes = target.GetResultBytes();
                Assert.That(bytes.Offset, Is.EqualTo(target.InitialBufferOffset));
                Assert.That(bytes.Count, Is.EqualTo(target.BytesUsed));
                // Returns same array if buffer contains single array and its segment refers entire array.
                Assert.That(target.GetResultBytes().Array, Is.SameAs(bytes.Array));
                // Returns same array if no allocation has been ocurred.
                Assert.That(bytes.Array, Is.SameAs(buffer));

                // Returns same array if no allocation has been ocurred.
                Assert.That(target.GetFinalBuffer(), Is.SameAs(buffer));

                // Only used contents are returned.
                Assert.That(bytes.ToArray(), Is.EqualTo(expected));
            }
            Assert.That(allocator.IsOnlyReallocateCalled(), Is.False);
        }
Beispiel #9
0
        public void TestSingleAllocation_Default_Scalar_EnoughSize(int offset)
        {
            var buffer = new byte[9 + offset];

            using (var target = CreatePacker(buffer, offset, true))
            {
                Assert.That(target.InitialBufferOffset, Is.EqualTo(offset));

                target.Pack(0x123456789AL);
                var expected = new byte[] { 0xD3, 0, 0, 0, 0x12, 0x34, 0x56, 0x78, 0x9A };
                Assert.That(target.BytesUsed, Is.EqualTo(expected.Length));

                var bytes = target.GetResultBytes();
                Assert.That(bytes.Offset, Is.EqualTo(target.InitialBufferOffset));
                Assert.That(bytes.Count, Is.EqualTo(target.BytesUsed));
                // Returns same array if buffer contains single array and its segment refers entire array.
                Assert.That(target.GetResultBytes().Array, Is.SameAs(bytes.Array));
                // Returns same array if no allocation has been ocurred.
                Assert.That(bytes.Array, Is.SameAs(buffer));

                // Returns same array if no allocation has been ocurred.
                Assert.That(target.GetFinalBuffer(), Is.SameAs(buffer));

                // Only used contents are returned.
                Assert.That(bytes.ToArray(), Is.EqualTo(expected));
            }
        }
        public void ItReturnsTheUpdatedChampionIfItWasUpdated()
        {
            int          expectedWinPercentage = 85;
            ChampionData championData          = new ChampionData {
                WinPercentage = expectedWinPercentage
            };

            _autoMocker.Get <IChampionRepository>().Expect(mock => mock.GetChampionData(_gameDefinitionId))
            .Return(championData);

            List <Champion> championList     = new List <Champion>();
            Champion        existingChampion = new Champion
            {
                Id               = _previousChampionId,
                PlayerId         = _playerChampionId,
                GameDefinitionId = _gameDefinitionId,
                GameDefinition   = new GameDefinition()
            };

            championList.Add(existingChampion);
            _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Champion>())
            .Return(championList.AsQueryable());

            Champion actualChampion = _autoMocker.ClassUnderTest.RecalculateChampion(_gameDefinitionId, _applicationUser, _dataContext);

            Assert.That(actualChampion, Is.SameAs(_savedChampion));
        }
Beispiel #11
0
        public void ItReturnsTheUpdatedChampionIfItWasUpdated()
        {
            int          expectedWinPercentage = 85;
            ChampionData championData          = new ChampionData {
                WinPercentage = expectedWinPercentage
            };

            championRepositoryMock.Expect(mock => mock.GetChampionData(gameDefinitionId))
            .Return(championData);

            List <Champion> championList     = new List <Champion>();
            Champion        existingChampion = new Champion
            {
                Id               = previousChampionId,
                PlayerId         = playerChampionId,
                GameDefinitionId = gameDefinitionId,
                GameDefinition   = new GameDefinition()
            };

            championList.Add(existingChampion);
            dataContextMock.Expect(mock => mock.GetQueryable <Champion>())
            .Return(championList.AsQueryable());

            Champion actualChampion = championRecalculator.RecalculateChampion(gameDefinitionId, applicationUser);

            Assert.That(actualChampion, Is.SameAs(savedChampion));
        }
        private static void AssertSource(ByteArrayUnpacker unpacker, byte[] array, int expectedOffset)
        {
            Assert.That(unpacker, Is.InstanceOf <MessagePackByteArrayUnpacker>());
            var byteArrayUnpacker = unpacker as MessagePackByteArrayUnpacker;

            Assert.That(byteArrayUnpacker.DebugSource, Is.SameAs(array));
            Assert.That(byteArrayUnpacker.Offset, Is.EqualTo(expectedOffset));
        }
Beispiel #13
0
        private void TestInnerExceptionConstructor_WithMessageAndInnerException_SetToMessageAndInnerException()
        {
            var message        = Guid.NewGuid().ToString();
            var innerException = new Exception();
            var target         = this._innerExceptionConstructor(message, innerException);

            Assert.That(target.Message, Is.Not.Null.And.StringContaining(message), "Message should contain message argument.");
            Assert.That(target.InnerException, Is.SameAs(innerException), "InnerException should contain innerException argument.");
            TestToString(target, typeof(T).Name + "()");
        }
        public void TestProperties()
        {
            byte typeCode = 0;
            var  body     = new byte[] { 1 };
            var  actual   = new MessagePackExtendedTypeObject(typeCode, body);

            Assert.That(actual.TypeCode, Is.EqualTo(typeCode));
            Assert.That(actual.Body, Is.SameAs(body));
            Assert.That(actual.GetBody(), Is.Not.SameAs(body).And.EqualTo(body));
        }
Beispiel #15
0
        public void GetMetadata_WithReadOnlyAttributeScalar()
        {
            IPropertyInformation propertyInfo      = GetPropertyInfo(typeof(ClassWithReferenceType <SimpleReferenceType>), "ReadOnlyAttributeScalar");
            PropertyReflector    propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider);

            Assert.That(GetUnderlyingType(propertyReflector), Is.SameAs(typeof(SimpleReferenceType)));

            IBusinessObjectProperty businessObjectProperty = propertyReflector.GetMetadata();

            Assert.That(businessObjectProperty, Is.InstanceOf(typeof(PropertyBase)));
            Assert.That(((PropertyBase)businessObjectProperty).PropertyInfo, Is.SameAs(propertyInfo));
            Assert.That(businessObjectProperty.Identifier, Is.EqualTo("ReadOnlyAttributeScalar"));
            Assert.That(businessObjectProperty.PropertyType, Is.SameAs(typeof(SimpleReferenceType)));
            Assert.That(businessObjectProperty.IsList, Is.False);
            Assert.That(businessObjectProperty.IsRequired, Is.False);
            Assert.That(businessObjectProperty.IsReadOnly(null), Is.True);
        }
Beispiel #16
0
        public void ItSetsTheApplicationUserOnTheApiControllerBase()
        {
            const string expectedToken = "TEST";

            request.Headers.Add(ApiAuthenticationAttribute.AUTH_HEADER, new[] { expectedToken });
            var expectedUser = new ApplicationUser
            {
                Id = "some id",
                CurrentGamingGroupId = 1
            };

            authTokenValidatorMock.Expect(mock => mock.ValidateAuthToken(expectedToken)).Return(expectedUser);

            attribute.OnActionExecuting(actionContext);
            ApplicationUser actualUser = ((ApiControllerBase)actionContext.ControllerContext.Controller).CurrentUser;

            Assert.That(actualUser, Is.SameAs(expectedUser));
        }
Beispiel #17
0
        public void TestConfigureClassic_Version0_9_DefaultIsReplaced()
        {
            var previous = SerializationContext.Default;

            try
            {
                var result = SerializationContext.ConfigureClassic(SerializationCompatibilityLevel.Version0_9);

                // result is old.
                Assert.That(result, Is.SameAs(previous));
                // result is default settings.
                Assert.That(result, Is.Not.Null);
                Assert.That(result.DefaultDateTimeConversionMethod, Is.EqualTo(DateTimeConversionMethod.Timestamp));
                Assert.That(result.CompatibilityOptions.PackerCompatibilityOptions, Is.EqualTo(PackerCompatibilityOptions.None));
                Assert.That(result.EnumSerializationOptions.SerializationMethod, Is.EqualTo(EnumSerializationMethod.ByName));
#if !AOT && !UNITY && !SILVERLIGHT
                Assert.That(result.SerializerOptions.GeneratorOption, Is.EqualTo(SerializationMethodGeneratorOption.Fast));
#endif // !AOT && !UNITY && !SILVERLIGHT
                Assert.That(result.SerializationMethod, Is.EqualTo(SerializationMethod.Array));

                // default is now classic 0.9
                Assert.That(SerializationContext.Default, Is.Not.Null);
                Assert.That(SerializationContext.Default.DefaultDateTimeConversionMethod, Is.EqualTo(DateTimeConversionMethod.Native));
                Assert.That(SerializationContext.Default.CompatibilityOptions.PackerCompatibilityOptions, Is.EqualTo(PackerCompatibilityOptions.None));
                Assert.That(SerializationContext.Default.EnumSerializationOptions.SerializationMethod, Is.EqualTo(EnumSerializationMethod.ByName));
#if !AOT && !UNITY && !SILVERLIGHT
                Assert.That(SerializationContext.Default.SerializerOptions.GeneratorOption, Is.EqualTo(SerializationMethodGeneratorOption.Fast));
#endif // !AOT && !UNITY && !SILVERLIGHT
                Assert.That(SerializationContext.Default.SerializationMethod, Is.EqualTo(SerializationMethod.Array));
            }
            finally
            {
                SerializationContext.Default = previous;
            }

            // Verify restore
            Assert.That(SerializationContext.Default.DefaultDateTimeConversionMethod, Is.EqualTo(DateTimeConversionMethod.Timestamp));
            Assert.That(SerializationContext.Default.CompatibilityOptions.PackerCompatibilityOptions, Is.EqualTo(PackerCompatibilityOptions.None));
            Assert.That(SerializationContext.Default.EnumSerializationOptions.SerializationMethod, Is.EqualTo(EnumSerializationMethod.ByName));
#if !AOT && !UNITY && !SILVERLIGHT
            Assert.That(SerializationContext.Default.SerializerOptions.GeneratorOption, Is.EqualTo(SerializationMethodGeneratorOption.Fast));
#endif // !AOT && !UNITY && !SILVERLIGHT
            Assert.That(SerializationContext.Default.SerializationMethod, Is.EqualTo(SerializationMethod.Array));
        }
 public void TestCreate_StreamOptionIsNull()
 {
     PackerUnpackerStreamOptions.AlwaysWrap = true;
     try
     {
         using (var stream = new MemoryStream())
             using (var unpacker = Unpacker.Create(stream, default(PackerUnpackerStreamOptions), default(UnpackerOptions)))
             {
                 Assert.That(unpacker, Is.InstanceOf <MessagePackStreamUnpacker>());
                 var streamUnpacker = unpacker as MessagePackStreamUnpacker;
                 Assert.That(streamUnpacker.DebugOwnsStream, Is.False);
                 Assert.That(streamUnpacker.DebugSource, Is.SameAs(stream));
             }
     }
     finally
     {
         PackerUnpackerStreamOptions.AlwaysWrap = false;
     }
 }
Beispiel #19
0
        public void TestConfigureClassic_DefaultIsReplaced()
        {
            var previous = SerializationContext.Default;

            try
            {
                var result = SerializationContext.ConfigureClassic();

                // result is old.
                Assert.That(result, Is.SameAs(previous));
                // result is default settings.
                Assert.That(result, Is.Not.Null);
                Assert.That(result.DefaultDateTimeConversionMethod, Is.EqualTo(DateTimeConversionMethod.Native));
                Assert.That(result.EnumSerializationMethod, Is.EqualTo(EnumSerializationMethod.ByName));
#if !XAMIOS && !UNITY
                Assert.That(result.GeneratorOption, Is.EqualTo(SerializationMethodGeneratorOption.Fast));
#endif // !XAMIOS && !UNITY
                Assert.That(result.SerializationMethod, Is.EqualTo(SerializationMethod.Array));

                // default is now classic
                Assert.That(SerializationContext.Default, Is.Not.Null);
                Assert.That(SerializationContext.Default.DefaultDateTimeConversionMethod, Is.EqualTo(DateTimeConversionMethod.UnixEpoc));
                Assert.That(SerializationContext.Default.EnumSerializationMethod, Is.EqualTo(EnumSerializationMethod.ByName));
#if !XAMIOS && !UNITY
                Assert.That(SerializationContext.Default.GeneratorOption, Is.EqualTo(SerializationMethodGeneratorOption.Fast));
#endif // !XAMIOS && !UNITY
                Assert.That(SerializationContext.Default.SerializationMethod, Is.EqualTo(SerializationMethod.Array));
            }
            finally
            {
                SerializationContext.Default = previous;
            }

            // Verify restore
            Assert.That(SerializationContext.Default.DefaultDateTimeConversionMethod, Is.EqualTo(DateTimeConversionMethod.Native));
            Assert.That(SerializationContext.Default.EnumSerializationMethod, Is.EqualTo(EnumSerializationMethod.ByName));
#if !XAMIOS && !UNITY
            Assert.That(SerializationContext.Default.GeneratorOption, Is.EqualTo(SerializationMethodGeneratorOption.Fast));
#endif // !XAMIOS && !UNITY
            Assert.That(SerializationContext.Default.SerializationMethod, Is.EqualTo(SerializationMethod.Array));
        }
Beispiel #20
0
        public void GetMetadata_WithReadOnlyMixedPropertyHavingSetterOnMixin()
        {
            IPropertyInformation propertyInfo = GetPropertyInfo(
                MixinTypeUtility.GetConcreteMixedType(typeof(ClassWithMixedProperty)),
                typeof(IMixinAddingProperty),
                "MixedReadOnlyPropertyHavingSetterOnMixin");

            Assertion.IsTrue(propertyInfo is MixinIntroducedPropertyInformation);

            PropertyReflector propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider);

            Assert.That(GetUnderlyingType(propertyReflector), Is.SameAs(typeof(string)));

            IBusinessObjectProperty businessObjectProperty = propertyReflector.GetMetadata();

            Assert.That(businessObjectProperty, Is.InstanceOf(typeof(PropertyBase)));
            Assert.That(((PropertyBase)businessObjectProperty).PropertyInfo, Is.SameAs(propertyInfo));
            Assert.That(businessObjectProperty.Identifier, Is.EqualTo("MixedReadOnlyPropertyHavingSetterOnMixin"));
            Assert.That(businessObjectProperty.PropertyType, Is.SameAs(typeof(string)));
            Assert.That(businessObjectProperty.IsList, Is.False);
            Assert.That(businessObjectProperty.IsRequired, Is.False);
            Assert.That(businessObjectProperty.IsReadOnly(null), Is.True);
        }
Beispiel #21
0
        public void LoadMostRecentFromInstance()
        {
            var saveData  = SaveDataTestImpl.NewSaveFile(nameof(LoadMostRecentFromInstance));
            var firstEdit = "First Edit";

            saveData.Word = firstEdit;
            saveData.Save(false);

            var saveData2  = SaveDataTestImpl.NewSaveFile(saveData.Nickname);
            var secondEdit = "Second Edit";

            saveData2.Word = secondEdit;
            saveData2.Save(false);

            Assert.That(saveData.Word, Is.EqualTo(firstEdit));
            Assert.That(saveData, Is.Not.SameAs(saveData2));

            var loadedSave = saveData.Reload();

            Assert.That(loadedSave, Is.SameAs(saveData));
            Assert.That(saveData.Word, Is.Not.EqualTo(firstEdit));
            Assert.That(saveData.Word, Is.EqualTo(secondEdit));
        }
Beispiel #22
0
        public void TestIssue70()
        {
            var serializer = MessagePackSerializer.Get <DBNull>(new SerializationContext());

#if !UNITY
            // Should not be created dynamically.
            Assert.That(serializer, Is.TypeOf(typeof(DefaultSerializers.System_DBNullMessagePackSerializer)));
#endif // !UNITY

            using (var buffer = new MemoryStream())
            {
                serializer.Pack(buffer, DBNull.Value);

                buffer.Position = 0;
                var packed = Unpacking.UnpackObject(buffer);
                Assert.That(packed.IsNil, packed.ToString());

                buffer.Position = 0;
                var unpacked = serializer.Unpack(buffer);
                Assert.That(Object.ReferenceEquals(unpacked, null), Is.False);
                Assert.That(unpacked, Is.SameAs(DBNull.Value));
            }
        }
Beispiel #23
0
 public static T ShouldBeSameAs <T>(this T actual, T expected)
 {
     Assert.That(actual, Is.SameAs(expected));
     return(actual);
 }
Beispiel #24
0
 public void InitializeShouldSetupProcessContextAwareScriptWorker()
 {
     InitializeWorkerWithValidSubTypeScript();
     Assert.That(worker.ScriptWorker, Is.InstanceOf <IProcessContextAware>());
     Assert.That(((IProcessContextAware)worker.ScriptWorker).ProcessContext, Is.SameAs(processContext));
 }
Beispiel #25
0
 public void InitializeShouldSetupGrinderContextAwareScriptWorker()
 {
     InitializeWorkerWithValidSubTypeScript();
     Assert.That(worker.ScriptWorker, Is.InstanceOf <IGrinderContextAware>());
     Assert.That(((IGrinderContextAware)worker.ScriptWorker).GrinderContext, Is.SameAs(grinderContextMock.Object));
 }
Beispiel #26
0
 public void InitializeShouldSetupDatapoolManagerAwareScriptWorker()
 {
     InitializeWorkerWithValidSubTypeScript();
     Assert.That(worker.ScriptWorker, Is.InstanceOf <IDatapoolManagerAware>());
     Assert.That(((IDatapoolManagerAware)worker.ScriptWorker).DatapoolManager, Is.SameAs(datapoolManagerMock.Object));
 }