Beispiel #1
0
        public void TestDictionaryExtension()
        {
            var list = SimplePoco.CreateDummyList(200);
            var dic  = list.CreateDictionaryFromPropertyValues(x => x.CharSequence);

            Assert.NotNull(dic);
        }
Beispiel #2
0
        public void TestShuffle()
        {
            var list         = SimplePoco.CreateDummyList(20);
            var shuffledList = list.Shuffle().ToList();

            Assert.True(list.Count == shuffledList.Count && list[0].ID != shuffledList[0].ID);
        }
Beispiel #3
0
        public SimplePoco ManuallyDeserialize()
        {
            var ogLength = BinPackResult.Length;
            var span     = BinPackResult.AsSpan();
            var poco     = new SimplePoco();

            poco.OldAccountId = MemoryMarshal.Read <long>(span);
            span = span.Slice(sizeof(long));

            poco.NewAccountId = MemoryMarshal.Read <long>(span);
            span = span.Slice(sizeof(long));

            poco.InfoId = MemoryMarshal.Read <long>(span);
            span        = span.Slice(sizeof(long));

            poco.LastChangeTime = DateTime.FromBinary(MemoryMarshal.Read <long>(span));
            span = span.Slice(sizeof(long));

            poco.FinalChangeTime = DateTime.FromBinary(MemoryMarshal.Read <long>(span));
            span = span.Slice(sizeof(long));

            poco.FastChangeTime = DateTime.FromBinary(MemoryMarshal.Read <long>(span));
            span = span.Slice(sizeof(long));

            poco.FinalCommentId = MemoryMarshal.Read <long>(span);
            span = span.Slice(sizeof(long));

            var readBytes = ogLength - span.Length;

            return(poco);
        }
Beispiel #4
0
        public void TestBatch()
        {
            var list      = SimplePoco.CreateDummyList(20);
            var batchList = list.Batch(2).ToList();

            Assert.True(batchList.Count == 10);
            batchList.ForEach(x => Assert.True(x.Count() == 2));
        }
Beispiel #5
0
        public void TestDictionarySinglePropertyExtension()
        {
            var list = SimplePoco.CreateDummyList(200);
            var dic  = list.CreateDictionaryFromSinglePropertyValues(x => x.ID.ToString());

            Assert.NotNull(dic);
            Assert.True(dic.ContainsKey(0.ToString()));
        }
        /// <summary>
        ///     Invoked by the client including the parameter.
        /// </summary>
        /// <param name="poco"></param>
        public void SomeRemoteMagic(SimplePoco poco)
        {
            ServerConsole.DebugLine("Recv poco obj from client! {0}: {1}", poco.Id, poco.Title);
            Debug.WriteLine(poco);

            // Get client proxy and invoke a answer to the poco
            var proxy = CurrentClient.GetClientProxy <ITestClient>();

            proxy.SomeClientMagic("Got your poco, ty client!");
        }
Beispiel #7
0
        public void ImportStringProp()
        {
            IDocumentColumn <SimplePoco> column = GetStringPropColumn();

            var poco = new SimplePoco();

            column.Parse(poco, StringPropValue);

            Assert.AreEqual(StringPropValue, poco.StringProp);
        }
Beispiel #8
0
        public void ExportInt32Prop()
        {
            IDocumentColumn <SimplePoco> column = GetInt32PropColumn();
            var poco = new SimplePoco {
                Int32Prop = Int32PropValue
            };
            string result = column.Serialize(poco);

            Assert.AreEqual(Int32PropValue.ToString(), result);
        }
Beispiel #9
0
        public void ImportInt32Prop()
        {
            IDocumentColumn <SimplePoco> column = GetInt32PropColumn();

            var poco = new SimplePoco();

            column.Parse(poco, Int32PropValue.ToString());

            Assert.AreEqual(Int32PropValue, poco.Int32Prop);
        }
        public void GetPrivateFieldValue()
        {
            // Arrange
            var componentUnderTest = new SimplePoco(new DateTime(2000, 1, 1));

            // Act
            var actual = componentUnderTest.GetPrivateFieldValue("MyNullableDateTimeField");

            // Assert
            actual.ShouldHaveSameValueAs(new DateTime(2000, 1, 1));
        }
Beispiel #11
0
        public void ExportStringProp()
        {
            IDocumentColumn <SimplePoco> column = GetStringPropColumn();

            var poco = new SimplePoco {
                StringProp = StringPropValue
            };
            string result = column.Serialize(poco);

            Assert.AreEqual(StringPropValue, result);
        }
Beispiel #12
0
        public void Equals_True()
        {
            // Arrange
            var componentUnderTest = new ReferenceEqualityComparer <object>();
            var simplePoco         = new SimplePoco();

            // Act
            var actual = componentUnderTest.Equals(simplePoco, simplePoco);

            // Assert
            actual.ShouldHaveSameValueAs(true);
        }
Beispiel #13
0
        public void Setup()
        {
            var fixture = new Fixture();

            poco          = fixture.Build <SimplePoco>().Create();
            PocoParser    = BinaryPacker.Shared.GetParser <SimplePoco>();
            MsgPackResult = MessagePackSerializer.Serialize(poco);
            var count = PocoParser.Serialize(poco, BinaryTarget);

            BinPackResult = new byte[count];
            BinaryTarget.AsSpan(0, count).CopyTo(BinPackResult);
        }
Beispiel #14
0
        public void ExportPoco()
        {
            IDocumentFormatDefinition <SimplePoco> definition = GetPocoDefinition();

            var poco = new SimplePoco {
                Int32Prop = Int32PropValue1, StringProp = StringPropValue1
            };
            string result = definition.Export(new List <SimplePoco> {
                poco
            });

            Assert.AreEqual(StringPropValue1 + "\t" + Int32PropValue1, result);
        }
        private static void InsertSample(IMongoCollection <SimplePoco> col)
        {
            var mySimplePoco = new SimplePoco()
            {
                Id         = 10,
                MongoQueue = new Queue <int>(),
                MongoList  = new List <long> {
                    10, 20, 30
                },
                MongoEnum      = MyEnum.Second,
                MongoDictonary = new Dictionary <string, int> {
                    { "First", 1 }, { "Second", 2 }
                },
            };

            mySimplePoco.MongoQueue.Enqueue(10);
            mySimplePoco.MongoQueue.Enqueue(20);
            mySimplePoco.MongoQueue.Enqueue(30);

            col.InsertOne(mySimplePoco);

            //
            var sampleDesc = new SimplePocoDescended()
            {
                MySimpleInt = 112,
                MyBooks     = new[]
                {
                    new Book()
                    {
                        Author = "Darko",
                        Title  = "Programming MongoDb"
                    },
                    new Book()
                    {
                        Author = "Phil",
                        Title  = "Crime in Chicago"
                    }
                },
                Id         = 20,
                MongoStack = new Stack <string>(),
                MongoList  = new List <long> {
                    1, 2, 3
                },
                MongoEnum = MyEnum.First
            };

            sampleDesc.MongoStack.Push("First pushed on MongoStack");
            sampleDesc.MongoStack.Push("Second pushed on MongoStack");
            col.InsertOne(sampleDesc);
        }
        public void SetPrivateFieldValue()
        {
            // Arrange
            var componentUnderTest = new SimplePoco();

            var expected = new SimplePoco(new DateTime(2000, 1, 1));

            // Act
            var actual = componentUnderTest.SetPrivateFieldValue("MyNullableDateTimeField", new DateTime(2000, 1, 1));

            // Assert
            componentUnderTest.ShouldHaveSameValueAs(expected);
            actual.ShouldHaveSameValueAs(expected);
        }
        public async Task SimplePocoRaisesExceptionWithDeleteAsync()
        {
            // --- Arrange
            var db = new SqlDatabase(DB_CONN);
            await db.ExecuteAsync(@"create table sample(Id int not null, Name varchar(50) null)");

            var record = new SimplePoco {
                Id = 1, Name = "First"
            };
            await db.InsertAsync(record);

            // --- Act
            await db.DeleteAsync(record);
        }
Beispiel #18
0
        public void SimplePocoRaisesExceptionWithUpdate()
        {
            // --- Arrange
            var db = new SqlDatabase(DB_CONN);

            db.Execute(@"create table sample(Id int not null, Name varchar(50) null)");
            var record = new SimplePoco {
                Id = 1, Name = "First"
            };

            db.Insert(record);

            // --- Act
            record.Name = "NewFirst";
            db.Update(record);
        }
Beispiel #19
0
        public void Property_Is_Mapped_To_Different_Property_Successfully()
        {
            var poco = new SimplePoco {
                Id = Guid.NewGuid(), Name = "TestName"
            };

            Mapper.Config <SimplePoco, SimpleDto>()
            .Ignore(p => p.Name)
            .MapProperty(p => p.AnotherName, d => d.Name);

            var dto = Mapper.Map <SimplePoco, SimpleDto>(poco);

            Assert.Equal(poco.Id, dto.Id);
            Assert.Null(dto.Name);
            Assert.Equal(poco.Name, dto.AnotherName);
        }
Beispiel #20
0
        public void Equals_False_WithNoTypeComparer()
        {
            // Arrange
            var componentUnderTest = new FieldValueEqualityComparer();

            FieldValueEqualityComparer.SetAssembliesWithTypesToUseValueSemanticsOn(new[] { typeof(SimplePoco).Assembly });

            var lhs = new SimplePoco();
            var rhs = new InheritedSimplePoco();

            // Act
            var actual = componentUnderTest.Equals(lhs, rhs);

            // Assert
            Assert.AreEqual(false, actual);
        }
        public void GetAllFieldsWithoutAttribute()
        {
            // Arrange
            var type     = typeof(SimplePoco);
            var expected = new List <FieldInfo>
            {
                type.GetField("MyPublicField"),
                type.GetField("MyNullableDateTimeField", BindingFlags.Instance | BindingFlags.NonPublic)
            };

            // Act
            var actual = new SimplePoco().GetAllFieldsWithoutAttribute <SimpleAttribute>();

            // Assert
            actual.ShouldHaveSameValueAs(expected);
        }
Beispiel #22
0
        public void SimplePocoRaisesExceptionWithDelete()
        {
            // --- Arrange
            var db = new FbDatabase(DB_CONN);

            db.BeginTransaction();
            db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))");
            db.CompleteTransaction();
            var record = new SimplePoco {
                Id = 1, Name = "First"
            };

            db.Insert(record);

            // --- Act
            db.Delete(record);
        }
        private TDest MapSimplePoco <TDest>(SimplePoco source) where TDest : class
        {
            var instance = new SimplePocoDTO()
            {
                Address     = source.Address,
                BirthDate   = source.BirthDate,
                CreatedOn   = source.CreatedOn,
                Email       = source.Email,
                Enabled     = source.Enabled,
                Id          = source.Id,
                Name        = source.Name,
                PhoneNumber = source.PhoneNumber,
                Town        = source.Town,
                ZipCode     = source.ZipCode
            };

            return(instance as TDest);
        }
Beispiel #24
0
        public void AreEqual_True_ComplexPoco()
        {
            // Arrange
            var componentUnderTest = new FieldValueEqualityComparer();

            FieldValueEqualityComparer.SetAssembliesWithTypesToUseValueSemanticsOn(new[] { typeof(SimplePoco).Assembly });
            var simplePoco = new SimplePoco {
                MyInt = 23
            };
            var lhs = new ComplexPoco
            {
                MyInt                = 1,
                MyStrings            = new[] { "1", "2" },
                SimplePocoArray      = new[] { new SimplePoco(), simplePoco },
                SimplePocoDictionary = new Dictionary <string, SimplePoco>
                {
                    { "1", new SimplePoco {
                          MyString = "test"
                      } },
                    { "2", simplePoco }
                },
                Bytes = Encoding.Default.GetBytes("test")
            };
            var rhs = new ComplexPoco
            {
                MyInt                = 1,
                MyStrings            = new[] { "1", "2" },
                SimplePocoArray      = new[] { new SimplePoco(), simplePoco },
                SimplePocoDictionary = new Dictionary <string, SimplePoco>
                {
                    { "1", new SimplePoco {
                          MyString = "test"
                      } },
                    { "2", simplePoco }
                },
                Bytes = Encoding.Default.GetBytes("test")
            };

            // Act
            var actual = FieldValueEqualityComparer.AreEqual(lhs, rhs);

            // Assert
            Assert.AreEqual(true, actual);
        }
Beispiel #25
0
        public void Inherited_Property_Is_Custom_Mapped_Successfully()
        {
            var poco = new SimplePoco {
                Id = Guid.NewGuid(), Name = "TestName", ValueString = "42", Timestamp = "12/25/2016 5:00 PM"
            };

            Mapper.Config <SimplePocoBase, SimpleDtoBase>()
            .MapProperty(d => d.Value, p => Int32.Parse(p.ValueString));

            Mapper.Config <SimplePocoBase, IDto>()
            .MapProperty(d => d.Timestamp, p => DateTime.Parse(p.Timestamp));

            var dto = Mapper.Map <SimplePoco, SimpleDto>(poco);

            Assert.Equal(poco.Id, dto.Id);
            Assert.Equal(poco.Name, dto.Name);
            Assert.Equal(42, dto.Value);
            Assert.Equal(DateTime.Parse("12/25/2016 5:00 PM"), dto.Timestamp);
        }
Beispiel #26
0
        public async Task SimplePocoRaisesExceptionWithUpdateAsync()
        {
            // --- Arrange
            var db = new FbDatabase(DB_CONN);
            await db.BeginTransactionAsync();

            await db.ExecuteAsync(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))");

            await db.CompleteTransactionAsync();

            var record = new SimplePoco {
                Id = 1, Name = "First"
            };
            await db.InsertAsync(record);

            // --- Act
            record.Name = "NewFirst";
            await db.UpdateAsync(record);
        }
Beispiel #27
0
        public static void Main(string[] args)
        {
            var endPoint = ProtocolEndPointBase.CreateEndPoint("tcp://127.0.0.1:6900");

            _client                      = new TestClientImplementation();
            _serviceClient               = ServiceClientBuilder.CreateClient <ITestServerService>(endPoint, _client);
            _serviceClient.Connected    += ClientOnConnected;
            _serviceClient.Disconnected += ClientOnDisconnected;
            _serviceClient.Connect();

            do
            {
                var cmd = Console.ReadLine();
                if (cmd == "exit")
                {
                    _serviceClient.Disconnect();
                }
                if (cmd == "void")
                {
                    _serviceClient.ServiceProxy.RemoteVoid();
                }
                if (cmd == "magic")
                {
                    var poco = new SimplePoco {
                        Id = 1, Title = "My POCO obj"
                    };
                    _serviceClient.ServiceProxy.SomeRemoteMagic(poco);
                }
                if (cmd == "ex")
                {
                    _serviceClient.ServiceProxy.RaiseTheException();
                }
            } while (_serviceClient.CommunicationState == CommunicationStates.Connected);


            Console.WriteLine("Press any key to exit.");
            Console.Read();
        }
Beispiel #28
0
        public void CouldSerializePocoArray()
        {
            var bytes = new byte[1000];
            var arr   = new SimplePoco[2];

            arr[0] = new SimplePoco
            {
                Value1 = 123,
                Value2 = "1230"
            };
            arr[1] = new SimplePoco
            {
                Value1 = 456,
                Value2 = "4560"
            };
            var len = BinarySerializer.Write(arr, bytes);

            SimplePoco[] arr2 = null;
            var          len2 = BinarySerializer.Read(bytes, ref arr2);

            Assert.AreEqual(len, len2);
            Assert.IsTrue(arr.SequenceEqual(arr2));
        }
Beispiel #29
0
        public void Equals_True_WithEqualityComparer_AtTopLevel()
        {
            // Arrange
            var componentUnderTest = new FieldValueEqualityComparer();

            FieldValueEqualityComparer.SetAssembliesWithTypesToUseValueSemanticsOn(new[] { typeof(SimplePoco).Assembly });

            var lhs = new SimplePoco
            {
                MyString = "1"
            };
            var rhs = new InheritedSimplePoco
            {
                MyString = "xxx"
            };

            // Act
            FieldValueEqualityComparer.AddFieldValueEqualityComparer(new SimplePocoEqualityComparer());
            var actual = componentUnderTest.Equals(lhs, rhs);

            // Assert
            Assert.AreEqual(true, actual);
        }
Beispiel #30
0
        public void CouldSerializePocoArray()
        {
            var bytes = new byte[1000];
            var value = new SimplePoco[2];

            value[0] = new SimplePoco
            {
                Value1 = 123,
                Value2 = "1230"
            };
            value[1] = new SimplePoco
            {
                Value1 = 456,
                Value2 = "4560"
            };
            var len0 = BinarySerializer.SizeOf(in value, out var pl);
            var len  = BinarySerializer.Write(value, bytes, in pl);

            SimplePoco[] arr2 = null;
            var          len2 = BinarySerializer.Read(bytes, out arr2);

            Assert.IsTrue(value.SequenceEqual(arr2), "Items are not equal");
            Assert.AreEqual(len, len2);
        }