Ejemplo n.º 1
0
        public void GetProjectLastRunIdTest(string projectName, int expected)
        {
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

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

                // Create the schema in the database
                using (var context = new EfDbContext(options))
                {
                    context.Database.EnsureCreated();
                    new GlutSeedData().Initialize(context);
                    var service = new EfResultStore(context, new EnvironmentService());

                    var actual = service.GetProjectLastRunId(projectName);

                    Assert.Equal(expected, actual);
                }
            }
            finally
            {
                connection.Close();
            }
        }
Ejemplo n.º 2
0
        public void AddTest()
        {
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

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

                // Create the schema in the database
                using (var context = new EfDbContext(options))
                {
                    var environment = new Mock <IEnvironment>();
                    environment.Setup(x => x.SystemDateTimeUtc).Returns(new DateTime(2019, 8, 1));
                    environment.Setup(x => x.UserName).Returns("TestUser");

                    context.Database.EnsureCreated();
                    var service = new EfResultStore(context, environment.Object);

                    var projectName = "TestProject";
                    var attributes  = new Dictionary <string, string>();
                    attributes.Add(nameof(projectName), projectName);

                    var start  = new DateTime(2019, 8, 1);
                    var result = new ThreadResult();
                    result.Add("/", start, start.AddSeconds(1), true, 200, 100, 200, 300, 400, "Headers", new Exception("Test"));

                    service.Add(projectName, -1, attributes, result);

                    var projects      = context.Projects.ToArray();
                    var runAttributes = context.RunAttributes.ToArray();
                    var results       = context.Results.ToArray();

                    var sb = new StringBuilder();
                    sb.Append(JsonConvert.SerializeObject(projects));
                    sb.AppendLine();
                    sb.Append(JsonConvert.SerializeObject(runAttributes));
                    sb.AppendLine();
                    sb.Append(JsonConvert.SerializeObject(results));

                    Approvals.Verify(sb.ToString());
                }
            }
            finally
            {
                connection.Close();
            }
        }