Example #1
0
            public async void ShouldReturnOkWithProjectItems()
            {
                IEnumerable <Project> expectedProjects;

                using (var context = new SimpleProjectTimeTrackerDbContext(Options))
                {
                    context.Projects.Add(new Project
                    {
                        Id           = 1,
                        CustomerName = "Microsoft",
                        Name         = "Sample web project for BUILD event",
                        DueDate      = new DateTime(2018, 7, 31),
                        HourlyRate   = 45
                    });
                    context.Projects.Add(new Project
                    {
                        Id           = 2,
                        CustomerName = "Amazon",
                        Name         = "Creation of a Picking List application",
                        DueDate      = new DateTime(2018, 9, 30),
                        HourlyRate   = 47
                    });
                    await context.SaveChangesAsync();

                    expectedProjects = await context.Projects.ToListAsync();
                }

                var result = await Sut.GetProjects(CancellationToken.None);

                var okResult      = Assert.IsType <OkObjectResult>(result);
                var okResultValue = Assert.IsAssignableFrom <IEnumerable <Project> >(okResult.Value);

                Assert.Equal(2, okResultValue.Count());
            }
Example #2
0
        public ProjectsControllerTests()
        {
            var builder = new DbContextOptionsBuilder <SimpleProjectTimeTrackerDbContext>();

            builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            Options   = builder.Options;
            DbContext = new SimpleProjectTimeTrackerDbContext(builder.Options);
            Sut       = new ProjectsController(DbContext);
        }
Example #3
0
        public static void SeedData(SimpleProjectTimeTrackerDbContext context)
        {
            var project1 = context.Projects.Add(new Project
            {
                Id            = 1,
                CustomerName  = "Microsoft",
                VatPercentage = 22,
                Name          = "Sample web project for BUILD event",
                DueDate       = new DateTime(2018, 7, 31),
                HourlyRate    = 45
            }).Entity;

            var project2 = context.Projects.Add(new Project
            {
                Id            = 2,
                CustomerName  = "Amazon",
                VatPercentage = 19.5m,
                Name          = "Creation of a Picking List application",
                DueDate       = new DateTime(2018, 9, 30),
                HourlyRate    = 47
            }).Entity;

            context.TimeRegistrations.Add(new TimeRegistrationEntity
            {
                ProjectId   = 1,
                Project     = project1,
                Date        = new DateTime(2018, 3, 24),
                HoursWorked = 6.5m,
                Accounted   = false
            });

            context.TimeRegistrations.Add(new TimeRegistrationEntity
            {
                ProjectId   = 1,
                Project     = project1,
                Date        = new DateTime(2018, 3, 23),
                HoursWorked = 5.5m,
                Accounted   = true
            });

            context.TimeRegistrations.Add(new TimeRegistrationEntity
            {
                ProjectId   = 2,
                Project     = project2,
                Date        = new DateTime(2018, 3, 23),
                HoursWorked = 2.5m,
                Accounted   = false
            });

            context.SaveChanges();
        }
Example #4
0
        public TimeRegistrationServiceTests()
        {
            var builder = new DbContextOptionsBuilder <SimpleProjectTimeTrackerDbContext>();

            builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            Options   = builder.Options;
            DbContext = new SimpleProjectTimeTrackerDbContext(builder.Options);
            DbContext.Database.EnsureCreated();
            DbContext.SeedDatabase();

            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MappingProfile());
            });

            Mapper = config.CreateMapper();

            Sut = new TimeRegistrationService(DbContext, Mapper);
        }
Example #5
0
 public InvoiceService(SimpleProjectTimeTrackerDbContext dbContext, IMapper mapper)
 {
     _dbContext = dbContext;
     _mapper    = mapper;
 }
Example #6
0
 public TimeRegistrationService(SimpleProjectTimeTrackerDbContext dbContext, IMapper mapper)
 {
     _dbContext = dbContext;
     _mapper    = mapper;
 }
 public ProjectsController(SimpleProjectTimeTrackerDbContext dbContext)
 {
     _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext), "A valid DB Context must be supplied.");
 }