public async Task TestGeneratedContact()
        {
            const string email            = "*****@*****.**";
            const string address          = "123 Entity Framework Ln";
            const string city             = "Redmond";
            const string state            = "WA";
            const string zip              = "99999";
            var          addressFormatted = string.Join(", ", address, city, state, zip);

            using (var db = new AppDb())
            {
                void TestContact(GeneratedContact contact)
                {
                    var csb = new FbConnectionStringBuilder(db.Database.GetDbConnection().ConnectionString);

                    /*var guidHexStr = csb.OldGuids
                     *  ? BitConverter.ToString(contact.Id.ToByteArray().Take(8).ToArray()).Replace("-", "")
                     *  : contact.Id.ToString().Replace("-", "").Substring(0, 16);*/
                    //var guidTicks = Convert.ToInt64("0x" + guidHexStr, 16);
                    //var guidDateTime = new DateTime(guidTicks);

                    //Assert.InRange(guidDateTime - DateTime.UtcNow, TimeSpan.FromSeconds(-5), TimeSpan.FromSeconds(5));

                    Assert.Equal(email, contact.Email);
                    Assert.Equal(addressFormatted, contact.Address);
                }

                var gen = new GeneratedContact
                {
                    Names = new JsonObject <List <string> >(new List <string> {
                        "Bob", "Bobby"
                    }),
                    ContactInfo = new JsonObject <Dictionary <string, string> >(new Dictionary <string, string>
                    {
                        { "Email", email },
                        { "Address", address },
                        { "City", city },
                        { "State", state },
                        { "Zip", zip },
                    }),
                };

                // test the entity after saving to the db
                db.GeneratedContacts.Add(gen);
                await db.SaveChangesAsync();

                TestContact(gen);

                // test the entity after fresh retreival from the database
                var genDb = await db.GeneratedContacts.FirstOrDefaultAsync(m => m.Id == gen.Id);

                TestContact(genDb);
            }
        }
コード例 #2
0
        public async Task TestGeneratedContact()
        {
            const string email            = "*****@*****.**";
            const string address          = "123 Entity Framework Ln";
            const string city             = "Redmond";
            const string state            = "WA";
            const string zip              = "99999";
            var          addressFormatted = string.Join(", ", address, city, state, zip);

            Action <GeneratedContact> testContact = contact =>
            {
                Assert.Equal(email, contact.Email);
                Assert.Equal(addressFormatted, contact.Address);
            };

            using (var db = new AppDb())
            {
                var gen = new GeneratedContact
                {
                    Names = new JsonObject <List <string> >(new List <string> {
                        "Bob", "Bobby"
                    }),
                    ContactInfo = new JsonObject <Dictionary <string, string> >(new Dictionary <string, string>
                    {
                        { "Email", email },
                        { "Address", address },
                        { "City", city },
                        { "State", state },
                        { "Zip", zip },
                    }),
                };

                // test the entity after saving to the db
                db.GeneratedContacts.Add(gen);
                await db.SaveChangesAsync();

                testContact(gen);

                // test the entity after fresh retreival from the database
                var genDb = await db.GeneratedContacts.FirstOrDefaultAsync(m => m.Id == gen.Id);

                testContact(genDb);
            }
        }