Beispiel #1
0
        public async Task CreateUserCreatesIntendedUser()
        {
            using (var database = new InMemoryCodeAFriendDatabase())
            {
                // Create user
                await database.CreateUser(User1Name);

                // Use a separate instance of the context to verify correct data was saved to database
                using (var context = database.NewContext())
                {
                    var user = await context.Users.FindAsync(User1Name);

                    Assert.Equal(1, context.Users.Count());
                    Assert.Equal(User1Name, user.Name);
                }
            }
        }
        public async Task AddProblemAddsSpecifiedProblem()
        {
            using (var database = new InMemoryCodeAFriendDatabase())
            {
                // CreateUser & Problem
                await database.CreateUser(User1Name);

                await database.CreateProblemForUser(User1Name, Problem1Name, Problem1Description);

                // Use a separate instance of the context to verify correct data was saved to database
                using (var context = database.NewContext())
                {
                    var user = await context.Users.Include(u => u.Problems).SingleAsync(u => u.Name == User1Name);

                    var problem = Assert.Single(user.Problems);
                    Assert.Equal(Problem1Name, problem.Name);
                    Assert.Equal(Problem1Description, problem.Description);
                }
            }
        }
Beispiel #3
0
        public async Task AddScriptAddsScriptToNewUser()
        {
            using (var database = new InMemoryCodeAFriendDatabase())
            {
                // Create user and script
                await database.CreateUser(User1Name);

                await database.CreateScriptForUser(User1Name, Script1Name, Script1Body, Script1Language);

                // Use a separate instance of the context to verify correct data was saved to database
                using (var context = database.NewContext())
                {
                    var user = await context.Users.Include(u => u.Scripts).SingleAsync(u => u.Name == User1Name);

                    var script = Assert.Single(user.Scripts);
                    Assert.Equal(Script1Name, script.Name);
                    Assert.Equal(Script1Body, script.Body);
                    Assert.Equal(Script1Language, script.Language);
                }
            }
        }
        public async Task AddTestCaseAddsTestCaseForProblem()
        {
            using (var database = new InMemoryCodeAFriendDatabase())
            {
                // Create user, problem, & testCase
                await database.CreateUser(User1Name);

                await database.CreateProblemForUser(User1Name, Problem1Name, Problem1Description);

                await database.CreateTestCaseForProblem(Problem1Name, 1, TestCase1Input, TestCase1Output);

                // Use a separate instance of the context to verify correct data was saved to database
                using (var context = database.NewContext())
                {
                    var problem = await context.Problems.Include(p => p.TestCases).SingleAsync(u => u.Name == Problem1Name);

                    var testCase = Assert.Single(problem.TestCases);
                    Assert.Equal((uint)1, testCase.Number);
                    Assert.Equal(TestCase1Input, testCase.Input);
                    Assert.Equal(TestCase1Output, testCase.ExpectedOutput);
                }
            }
        }