コード例 #1
0
        public void RemoveMember_AddMember()
        {
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();
            try
            {
                var options = new DbContextOptionsBuilder <ScrumContext>()
                              .UseSqlite(connection)
                              .Options;

                // Create the schema in the database
                using (var context = new ScrumContext(options))
                {
                    context.Database.EnsureCreated();
                }

                // Run the test against one instance of the context
                using (var context = new ScrumContext(options))
                {
                    var service = new GroupRepository(context);
                    var user    = new User {
                        username = "******"
                    };
                    GroupMember groupMember = new GroupMember {
                        user = user, role = "Developer", groupID = 1
                    };
                    var added        = service.AddMember(groupMember);
                    var existingItem = context.GroupMembers.Any(x => x.Username.Equals("Andrew"));
                    Assert.AreEqual(true, existingItem);
                    bool removed     = service.RemoveMember(groupMember);
                    bool removedItem = context.GroupMembers.Any(x => x.Username.Equals("Andrew"));
                    Assert.AreEqual(false, removedItem);
                    Assert.AreEqual(true, removed);
                }
            }
            finally
            {
                connection.Close();
            }
        }
コード例 #2
0
        public void ChangeRole()
        {
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();
            try
            {
                var options = new DbContextOptionsBuilder <ScrumContext>()
                              .UseSqlite(connection)
                              .Options;

                // Create the schema in the database
                using (var context = new ScrumContext(options))
                {
                    context.Database.EnsureCreated();
                }

                // Run the test against one instance of the context
                using (var context = new ScrumContext(options))
                {
                    var  service = new GroupRepository(context);
                    User user    = new User();
                    user.username = "******";
                    GroupMember groupMember = new GroupMember();
                    groupMember.user    = user;
                    groupMember.role    = "Product Owner";
                    groupMember.groupID = 1;
                    service.AddMember(groupMember);
                    Assert.AreEqual("Product Owner", context.GroupMembers.Find("dave").GroupRole);
                    groupMember.role = "Scrum Master";
                    service.ChangeRole(groupMember);
                    Assert.AreEqual("Scrum Master", context.GroupMembers.Find("dave").GroupRole);
                }
            }
            finally
            {
                connection.Close();
            }
        }