Example #1
0
 public void SpentTimeValueObject_DontCreateWrongAmount(int[] data)
 {
     for (int i = 0; i < data.Length; i++)
     {
         Action act = () => SpentTime.FromInt(data[i]);
         act.Should().Throw <ArgumentException>();
     }
 }
Example #2
0
 public void SpentTimeValueObject_CreatingFromInt(int[] data)
 {
     for (int i = 0; i < data.Length; i++)
     {
         var spentTime = SpentTime.FromInt(data[i]);
         spentTime.Amount.Should().Be(data[i]);
     }
 }
Example #3
0
        public void Save(SpentTime spentTime)
        {
            if (spentTime.Id == 0)
            {
                _context.SpentTimes.Add(spentTime);
            }

            _context.SaveChanges();
        }
Example #4
0
 /// <summary>Создание новой карточки учета времени</summary>
 /// <param name="request">Запрос на создание карточки</param>
 /// <returns>Новая карточка учета времени</returns>
 public static SheetAggregate CreateFromRequest(SheetCreateRequest request)
 {
     return(new SheetAggregate()
     {
         Id = Guid.NewGuid(),
         Amount = SpentTime.FromInt(request.Amount),
         ContractId = request.ContractId,
         Date = request.Date,
         EmployeeId = request.EmployeeId,
         ServiceId = request.ServiceId,
         IsDeleted = false,
     });
 }
Example #5
0
        public void DeleteSpentTime()
        {
            using (var fixture = new FixtureInit("http://localhost"))
            {
                //INIT
                var repository = new SpentTimesRepository(fixture.Setup.Context);

                var spentTime = new SpentTime()
                {
                    Amount      = 30,
                    Description = "Test description 1",
                    ProjectId   = fixture.Setup.Project.Id
                };

                repository.Save(spentTime);

                //ACT
                repository.Delete(spentTime);

                //POST
                var foundSpentTime = repository.SpentTimes.WithId(spentTime.Id);
                Assert.That(foundSpentTime, Is.Null);
            }
        }
Example #6
0
        public void InsertSpentTime()
        {
            using (var fixture = new FixtureInit("http://localhost"))
            {
                //INIT
                var repository = new SpentTimesRepository(fixture.Setup.Context);

                //ACT
                var spentTime = new SpentTime()
                {
                    Amount      = 30,
                    Description = "Test description 1",
                    ProjectId   = fixture.Setup.Project.Id
                };

                repository.Save(spentTime);

                //POST
                var actual = repository.SpentTimes.WithId(spentTime.Id);
                Assert.That(actual, Is.Not.Null);
                Assert.That(actual.Description, Is.EqualTo("Test description 1"));
                Assert.That(actual.ProjectId, Is.EqualTo(fixture.Setup.Project.Id));
            }
        }
Example #7
0
        public void Configure(EntityTypeBuilder <SheetAggregate> builder)
        {
            builder.ToTable("sheets");

            builder.Property(x => x.Id)
            .ValueGeneratedNever()
            .HasColumnName("Id");

            builder
            .HasOne(sheet => sheet.Invoice)
            .WithMany(invoice => invoice.Sheets)
            .HasForeignKey("InvoiceId");

            builder
            .HasOne(sheet => sheet.Contract)
            .WithMany(contract => contract.Sheets)
            .HasForeignKey("ContractId");

            builder
            .HasOne(sheet => sheet.Service)
            .WithMany(service => service.Sheets)
            .HasForeignKey("ServiceId");

            builder
            .HasOne(sheet => sheet.Employee)
            .WithMany(employee => employee.Sheets)
            .HasForeignKey("EmployeeId");

            //Value Objects
            var converter = new ValueConverter <SpentTime, int>(
                v => v.Amount,
                v => SpentTime.FromInt(v));

            builder.Property(x => x.Amount)
            .HasConversion(converter);
        }
Example #8
0
 public void Delete(SpentTime spentTime)
 {
     _context.SpentTimes.Remove(spentTime);
     _context.SaveChanges();
 }