Ejemplo n.º 1
0
        public async Task EnsureSeedData()
        {
            if (await _usermanager.FindByEmailAsync("*****@*****.**") == null)
            {
                var user = new TCMUser()
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                };

                await _usermanager.CreateAsync(user, "P@ssw0rd!");
            }

            //method .Any returns bool telling if there are any elements in database
            if (!_context.TestCases.Any())
            {
                //creating an instance of the testcase
                var testCase = new TestCase()
                {
                    Name          = "Sample test case.",
                    Preconditions = "Preconditions for sample test case.",
                    Steps         = new List <Step>
                    {
                        new Step()
                        {
                            Order = 0, Name = "First step for first test case.", Result = "Expected to pass.", Status = "Passed"
                        },
                        new Step()
                        {
                            Order = 1, Name = "Second step for first test case.", Result = "Expected to pass.", Status = "Passed"
                        },
                    },
                    DateCreated = DateTime.UtcNow,
                    UserName    = "******",
                };
                //adding testcase to the context
                _context.TestCases.Add(testCase);
                //will add steps to separate table
                _context.Steps.AddRange(testCase.Steps);

                var nextTestCase = new TestCase()
                {
                    Name          = "Next sample test case.",
                    Preconditions = "Preconditions for next sample test case.",
                    Steps         = new List <Step>
                    {
                        new Step()
                        {
                            Order = 0, Name = "First step for second test case.", Result = "Expected to pass.", Status = "Passed"
                        },
                        new Step()
                        {
                            Order = 1, Name = "Second step for second test case.", Result = "Expected to pass.", Status = "Passed"
                        },
                    },
                    DateCreated = DateTime.UtcNow,
                    UserName    = "******",
                };

                _context.TestCases.Add(nextTestCase);

                _context.Steps.AddRange(nextTestCase.Steps);

                //and now we are saving all the added changes
                await _context.SaveChangesAsync();
            }
        }
Ejemplo n.º 2
0
 //asynchronous call - task that wraps a bool
 public async Task <bool> SaveChangesAsync()
 {
     //methods SaveChanges and SaveChangesAsync return an interger that represents number of rows affected
     return((await _contex.SaveChangesAsync()) > 0);
 }