Exemple #1
0
        public void CreateContactState_Succeeds()
        {
            var options = new DbContextOptionsBuilder <MainContext>()
                          .UseInMemoryDatabase(databaseName: "CreateContactState_adds_to_context")
                          .Options;

            // Run the test against one instance of the context
            using (var context = new MainContext(options))
            {
                var sut   = new MainRepository(context);
                var guid  = Guid.NewGuid();
                var name  = "new";
                var state = sut.CreateContactState(guid, name);

                Assert.Equal(state, context.ContactStates.Local.First());

                sut.PersistChanges();

                Assert.Equal(state, context.ContactStates.First());
                Assert.Equal(1, context.ContactStates.Count());
                Assert.Equal(guid, context.ContactStates.First().Guid);
            }

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new MainContext(options))
            {
                Assert.Equal(1, context.ContactStates.Count());
            }
        }