Exemple #1
0
        public void ShouldCreateNewModel()
        {
            // Arrange
            Guid     expectedId            = Guid.NewGuid();
            Guid     expectedHouseholdId   = Guid.NewGuid();
            Guid     expectedExpenseTypeId = Guid.NewGuid();
            string   expectedName          = "Name";
            string   expectedDescription   = "Description";
            decimal  expectedAmount        = 102.12m;
            DateTime expectedDate          = DateTime.Now;
            DateTime expectedStart         = DateTime.Now;
            DateTime expectedEnd           = DateTime.Now.AddYears(1);
            Period   expectedPeriod        = Period.Create(expectedStart, expectedEnd);

            // Act
            Expense actual = Expense.Create(expectedId, expectedHouseholdId, expectedExpenseTypeId,
                                            expectedName, expectedDescription, expectedAmount, expectedDate, expectedPeriod);

            // Assert
            Assert.IsTrue(actual != null);
            Assert.IsTrue(actual.Id == expectedId);
            Assert.IsTrue(actual.HouseholdId == expectedHouseholdId);
            Assert.IsTrue(actual.ExpenseTypeId == expectedExpenseTypeId);
            Assert.IsTrue(actual.Name == expectedName);
            Assert.IsTrue(actual.Description == expectedDescription);
            Assert.IsTrue(actual.Amount == expectedAmount);
            Assert.IsTrue(actual.Date == expectedDate);
            Assert.IsTrue(actual.Period != null);
            Assert.IsTrue(actual.Period.Equals(expectedPeriod));
            Assert.IsTrue(!string.IsNullOrEmpty(actual.SearchValue));
        }
Exemple #2
0
        public void ShouldModifyModel()
        {
            // Arrange
            Guid     expectedId            = Guid.NewGuid();
            Guid     expectedHouseholdId   = Guid.NewGuid();
            Guid     expectedExpenseTypeId = Guid.NewGuid();
            string   expectedName          = "ModifiedName";
            string   expectedDescription   = "ModifiedDescription";
            decimal  expectedAmount        = 0.12m;
            DateTime expectedDate          = DateTime.Now.AddDays(1);
            DateTime expectedStart         = DateTime.Now.AddDays(1);
            DateTime expectedEnd           = DateTime.Now.AddYears(2);
            Period   expectedPeriod        = Period.Create(expectedStart, expectedEnd);

            Expense actual = Expense.Create(expectedId, expectedHouseholdId, Guid.NewGuid(),
                                            "Name", "Description", 100.12M, DateTime.Now, Period.Create(DateTime.Now, DateTime.Now));

            // Act
            actual.Modify(expectedExpenseTypeId, expectedName, expectedDescription, expectedAmount,
                          expectedDate, Period.Create(expectedStart, expectedEnd), 1);

            // Assert
            Assert.IsTrue(actual.Id == expectedId);
            Assert.IsTrue(actual.Name == expectedName);
            Assert.IsTrue(actual.Description == expectedDescription);
            Assert.IsTrue(actual.Date == expectedDate);
            Assert.IsTrue(actual.Amount == expectedAmount);
            Assert.IsTrue(actual.ExpenseTypeId == expectedExpenseTypeId);
            Assert.IsTrue(actual.Period != null);
            Assert.IsTrue(actual.Period.PeriodStart == expectedStart);
            Assert.IsTrue(actual.Period.PeriodEnd == expectedEnd);
            Assert.IsTrue(!string.IsNullOrEmpty(actual.SearchValue));
        }
Exemple #3
0
        public void Second_semesters_always_starts_on_the_second_week_of_february(int createYear, int createMonth, int createDay,
                                                                                  int expectedYear, int expectedMonth, int expectedDay)
        {
            var period = Period.Create(new DateTime(createYear, createMonth, createDay));

            period.IsSuccess.Should().BeTrue();
            period.Value.StartDate.Should().Be(new DateTime(expectedYear, expectedMonth, expectedDay));
        }
Exemple #4
0
        public void Gives_the_amount_of_days_passed_in_the_semester(int year, int month, int day, int sinceYear, int sinceMonth, int sinceDay, int actualDaysPassed)
        {
            var period = Period.Create(new DateTime(year, month, day)).Value;

            var daysPassed = period.TimePassedInsideSemesterSince(new DateTime(sinceYear, sinceMonth, sinceDay));

            daysPassed.Should().Be(actualDaysPassed.Days());
        }
Exemple #5
0
        public void Period_to_string_shows_nice_formatting(int year, int month, int day, string expectedPeriod)
        {
            var period = Period.Create(new DateTime(year, month, day));

            var periodString = period.Value.ToString();

            periodString.Should().Be(expectedPeriod);
        }
Exemple #6
0
 public IActionResult OnGet()
 {
     StudentGroup = new()
     {
         StartDate = Period
                     .Create(DateTime.UtcNow).Value
                     .StartDate
     };
     return(Page());
 }
        public async Task HandleAsync(ModifyExpenseCommand message, CancellationToken token = default(CancellationToken))
        {
            var expense = await _expenses.GetByIdAsync(message.ExpenseId);

            if (expense == null)
            {
                throw new HouseholdException($"Expense {message.ExpenseId} doesn't exists");
            }
            expense.Modify(message.ExpenseTypeId, message.Name, message.Description, message.Amount,
                           message.Date, Period.Create(message.PeriodStart, message.PeriodEnd), message.Version);
            await _expenses.SaveChangesAsync(token);
        }
        public void ShouldCreateNewModel()
        {
            // Arrange
            DateTime expectedStart = DateTime.Now;
            DateTime expectedEnd   = DateTime.Now.AddYears(1);

            // Act
            Period actual = Period.Create(expectedStart, expectedEnd);

            // Assert
            Assert.IsTrue(actual != null);
            Assert.IsTrue(actual.PeriodStart == expectedStart);
            Assert.IsTrue(actual.PeriodEnd == expectedEnd);
        }
        public async Task Reload_all_events_with_their_domainEvent_infos()
        {
            await Make.TestFile("reload.es").AndExecute(async env =>
            {
                var store = new FileEventStoreWithCache(new CustomJsonSerializer(), env.FilePath);

                var period = Period.Create(PeriodName.From(1, 2007));
                period.AddSpending(Amount.From(5), Label.From("test"), Pair.First, SpendingCategory.Common);
                await store.Save(period.UncommittedEvents.GetStream());

                var store2 = new FileEventStoreWithCache(new CustomJsonSerializer(), env.FilePath);

                var allEvents = await store2.GetEvents(a => true);
                allEvents.Any(a => a.AggregateId.IsEmpty()).Should().BeFalse();
            });
        }
        public async Task Retrieve_last_sequence()
        {
            await Make.TestFile("Sequence.es").AndExecute(async env =>
            {
                var store = new FileEventStoreWithCache(new CustomJsonSerializer(), env.FilePath);

                var period = Period.Create(PeriodName.From(1, 2007));
                period.AddSpending(Amount.From(5), Label.From("test"), Pair.First, SpendingCategory.Common);
                period.AddSpending(Amount.From(5), Label.From("test2"), Pair.First, SpendingCategory.Common);
                period.AddSpending(Amount.From(5), Label.From("test3"), Pair.First, SpendingCategory.Common);
                period.AddSpending(Amount.From(5), Label.From("test4"), Pair.First, SpendingCategory.Common);

                await store.Save(period.UncommittedEvents.GetStream());

                var lastSequence = await store.GetLastSequence(period.AggregateId);
                lastSequence.Should().Be(8);
            });
        }
Exemple #11
0
        public DiscountCuponFakeReaderRepository()
        {
            _cupons = new List <DiscountCupon>();

            var cupon1 = new DiscountCupon("XPTO1", 5, Period.Monthly);
            var cupon2 = new DiscountCupon("XPTO2", 10, Period.Monthly);
            var cupon3 = new DiscountCupon("XPTO3", 15, Period.Monthly);
            var cupon4 = new DiscountCupon("XPTO4", 20, Period.Monthly);
            var cupon5 = new DiscountCupon("XPTO5", 25, Period.Monthly);
            var cupon6 = new DiscountCupon("XPTO6", 30, Period.Monthly);
            var cupon7 = new DiscountCupon("XPTO8", 5, Period.Create(new DateTime(2008, 12, 25), new DateTime(2008, 12, 26)));

            _cupons.Add(cupon1);
            _cupons.Add(cupon2);
            _cupons.Add(cupon3);
            _cupons.Add(cupon4);
            _cupons.Add(cupon5);
            _cupons.Add(cupon6);
            _cupons.Add(cupon7);
        }
        public async Task <Result> HandleAsync(Request request)
        {
            var studentGroup = Maybe <StudentGroup> .From(await _context.Groups.FindAsync(request.Id));

            var nameResult       = Name.Create(request.Name);
            var periodResult     = Period.Create(request.StartDate);
            var validationResult = Result.Combine(nameResult, periodResult);

            if (validationResult.IsFailure)
            {
                return(validationResult);
            }


            return(await studentGroup.ToResult("Group does not exist")
                   .Check(group => group.UpdateGroup(nameResult.Value, periodResult.Value, request.Mnemonic))
                   .Tap(async() => await _context.SaveChangesAsync()));

            ;
        }
        public async Task <String> ReservationAsync(String housingId, String userId, decimal amount, DateTime checkIn, DateTime checkOut)
        {
            if (checkIn == null || checkOut == null)
            {
                return(StatusConstant.BookedError);
            }

            var housing = await _repositoryHousing.GetEntityAsync(x => x.Id == housingId);

            var reservationDtos   = new List <Reservation>();
            var reservstionPeriod = Period.Create(checkIn, checkOut);
            var reservations      = await _repositoryReservation.GetAll().AsNoTracking().ToListAsync();

            reservations = reservations.Where(x => Period.Create(x.CheckIn, x.CheckOut).IsIntersectOrInclude(reservstionPeriod)).ToList();
            reservations.RemoveAll(x => x.HousingId != housingId);

            if (reservations.Any())
            {
                return(StatusConstant.BookedError);
            }

            var user = await _repositoryUser.GetEntityAsync(x => x.Id == userId);

            var reservation = new Reservation
            {
                HousingId = housing.Id,
                Housing   = housing,
                User      = user,
                UserId    = userId,
                CheckIn   = checkIn,
                CheckOut  = checkOut,
                Amount    = amount,
                State     = StateConstant.requested
            };

            await _repositoryReservation.CreateAsync(reservation);

            await _repositoryReservation.SaveChangesAsync();

            return(StatusConstant.Booked);
        }
        public async Task Write_in_eventstore_from_multiple_thread()
        {
            await Make.TestFile("MultiThread.es").AndExecute(async env =>
            {
                var store = new FileEventStoreWithCache(new CustomJsonSerializer(), env.FilePath);

                var period = Period.Create(PeriodName.From(1, 2007));
                period.AddSpending(Amount.From(5), Label.From("test"), Pair.First, SpendingCategory.Common);
                period.AddSpending(Amount.From(5), Label.From("test2"), Pair.First, SpendingCategory.Common);
                period.AddSpending(Amount.From(5), Label.From("test3"), Pair.First, SpendingCategory.Common);
                period.AddSpending(Amount.From(5), Label.From("test4"), Pair.First, SpendingCategory.Common);

                var t1 = Task.Run(() => store.Save(period.UncommittedEvents.GetStream()));
                var t2 = Task.Run(() => store.Save(period.UncommittedEvents.GetStream()));

                Task.WaitAll(t1, t2);

                var lastSequence = await store.GetLastSequence(period.AggregateId);
                lastSequence.Should().Be(8);
            });
        }
Exemple #15
0
        public IActionResult CheckPeriod([FromBody] PeriodCheckModel periods)
        {
            if (periods == null)
            {
                return(BadRequest("Voeg a.u.b twee geldige periodes toe"));
            }

            var firstPeriodResult  = Period.Create(periods.Period1[0], periods.Period1[1]);
            var secondPeriodResult = Period.Create(periods.Period2[0], periods.Period2[1]);

            var combinedResult = Result.Combine(firstPeriodResult, secondPeriodResult);

            if (combinedResult.IsFailure)
            {
                return(BadRequest(combinedResult.Error.FirstOrDefault()));
            }

            var periodsOverlap = firstPeriodResult.Value.OverlapsWith(secondPeriodResult.Value);

            return(Ok(new { overlap = periodsOverlap }));
        }
Exemple #16
0
        public void ShouldHaveModifiedEvent()
        {
            // Arrange
            Guid     expectedId            = Guid.NewGuid();
            Guid     expectedExpenseTypeId = Guid.NewGuid();
            string   expectedName          = "ModifiedName";
            string   expectedDescription   = "ModifiedDescription";
            decimal  expectedAmount        = 0.12m;
            DateTime expectedDate          = DateTime.Now.AddDays(1);
            DateTime expectedStart         = DateTime.Now.AddDays(1);
            DateTime expectedEnd           = DateTime.Now.AddYears(2);

            Expense actual = Expense.Create(expectedId, Guid.NewGuid(), Guid.NewGuid(),
                                            "Name", "Description", 100.12M, DateTime.Now, Period.Create(DateTime.Now, DateTime.Now));

            actual.FlushUncommitedEvents();

            // Act
            actual.Modify(expectedExpenseTypeId, expectedName, expectedDescription, expectedAmount,
                          expectedDate, Period.Create(expectedStart, expectedEnd), 1);

            // Assert
            Assert.IsTrue(actual.Events != null);
            Assert.IsTrue(actual.Events.Count == 1);
            var events = actual.FlushUncommitedEvents();

            Assert.IsTrue(events != null);
            Assert.IsTrue(events.Length == 1);
            Assert.IsTrue(events[0] is ExpenseModifiedEvent);
            ExpenseModifiedEvent @event = events[0] as ExpenseModifiedEvent;

            Assert.IsTrue(@event.EntityId == expectedId);
            Assert.IsTrue(@event.ExpenseTypeId == expectedExpenseTypeId);
            Assert.IsTrue(@event.Amount == expectedAmount);
            Assert.IsTrue(@event.Description == expectedDescription);
            Assert.IsTrue(@event.Name == expectedName);
            Assert.IsTrue(@event.Date == expectedDate);
            Assert.IsTrue(@event.PeriodStart == expectedStart);
            Assert.IsTrue(@event.PeriodEnd == expectedEnd);
        }
Exemple #17
0
        public static IMapper Create()
        {
            var configuration = new MapperConfiguration(c =>
            {
                // TODO: try reversemap https://stackoverflow.com/questions/13490456/automapper-bidirectional-mapping-with-reversemap-and-formember
                //c.AddExpressionMapping();
                c.IgnoreUnmapped();
                //c.AllowNullCollections = true;
                c.CreateMap <Order, DtoOrder>()
                .ForMember(d => d.Id, o => o.MapFrom(s => s.Id))
                .ForMember(d => d.Customer, o => o.MapFrom(s => s.CustomerNumber))
                .ForMember(d => d.Order, o => o.MapFrom(s => s.OrderNumber))
                .ForMember(d => d.FirstName, o => o.MapFrom(s => s.FirstName))
                .ForMember(d => d.LastName, o => o.MapFrom(s => s.LastName))
                .ForMember(d => d.Location, o => o.MapFrom(s => s.Region))
                .ForMember(d => d.Total, o => o.MapFrom(s => s.Total))
                .ForMember(d => d.DeliveryStartDate, o => o.MapFrom(s => s.DeliveryPeriod != null ? s.DeliveryPeriod.StartDate : null))
                .ForMember(d => d.DeliveryEndDate, o => o.MapFrom(s => s.DeliveryPeriod != null ? s.DeliveryPeriod.EndDate : null))
                .ForMember(d => d.ReturnStartDate, o => o.MapFrom(s => s.ReturnPeriod != null ? s.ReturnPeriod.StartDate : null))
                .ForMember(d => d.ReturnEndDate, o => o.MapFrom(s => s.ReturnPeriod != null ? s.ReturnPeriod.EndDate : null))
                .ForMember(d => d.TenantId, o => o.MapFrom(s => s.TenantId))
                .ForMember(d => d.State, o => o.Ignore());

                c.CreateMap <DtoOrder, Order>()
                .ForMember(d => d.Id, o => o.MapFrom(s => s.Id))
                .ForMember(d => d.CustomerNumber, o => o.MapFrom(s => s.Customer))     // can map to private set
                .ForMember(d => d.OrderNumber, o => o.MapFrom(s => s.Order))
                .ForMember(d => d.FirstName, o => o.MapFrom(s => s.FirstName))
                .ForMember(d => d.LastName, o => o.MapFrom(s => s.LastName))
                .ForMember(d => d.Region, o => o.MapFrom(s => s.Location))
                .ForMember(d => d.DeliveryPeriod, o => o.MapFrom(s => Period.Create(s.DeliveryStartDate, s.DeliveryEndDate))) // can map to private set
                .ForMember(d => d.ReturnPeriod, o => o.MapFrom(s => Period.Create(s.ReturnStartDate, s.ReturnEndDate)))       // can map to private set
                .ForMember(d => d.TenantId, o => o.MapFrom(s => s.TenantId))
                .ForMember(d => d.Total, o => o.MapFrom(s => s.Total));
            });

            configuration.AssertConfigurationIsValid();
            return(configuration.CreateMapper());
        }
Exemple #18
0
        public void ShouldHaveCreatedEvent()
        {
            // Arrange
            Guid     expectedId            = Guid.NewGuid();
            Guid     expectedHouseholdId   = Guid.NewGuid();
            Guid     expectedExpenseTypeId = Guid.NewGuid();
            string   expectedName          = "Name";
            string   expectedDescription   = "Description";
            decimal  expectedAmount        = 102.12m;
            DateTime expectedDate          = DateTime.Now;
            DateTime expectedStart         = DateTime.Now;
            DateTime expectedEnd           = DateTime.Now.AddYears(1);
            Period   expectedPeriod        = Period.Create(expectedStart, expectedEnd);

            // Act
            Expense actual = Expense.Create(expectedId, expectedHouseholdId, expectedExpenseTypeId,
                                            expectedName, expectedDescription, expectedAmount, expectedDate, expectedPeriod);

            // Assert
            Assert.IsTrue(actual != null);
            Assert.IsTrue(actual.Events != null);
            Assert.IsTrue(actual.Events.Count == 1);
            var events = actual.FlushUncommitedEvents();

            Assert.IsTrue(events != null);
            Assert.IsTrue(events.Length == 1);
            Assert.IsTrue(events[0] is ExpenseCreatedEvent);
            ExpenseCreatedEvent @event = events[0] as ExpenseCreatedEvent;

            Assert.IsTrue(@event.EntityId == expectedId);
            Assert.IsTrue(@event.HouseholdId == expectedHouseholdId);
            Assert.IsTrue(@event.ExpenseTypeId == expectedExpenseTypeId);
            Assert.IsTrue(@event.Description == expectedDescription);
            Assert.IsTrue(@event.Name == expectedName);
            Assert.IsTrue(@event.Date == expectedDate);
            Assert.IsTrue(@event.PeriodStart == expectedStart);
            Assert.IsTrue(@event.PeriodEnd == expectedEnd);
        }
Exemple #19
0
        public async Task ShouldModifyExisting()
        {
            // Arrange
            Guid    expectedId   = Guid.NewGuid();
            string  expectedName = "Modified Name";
            Expense entity       = Expense.Create(expectedId, Guid.NewGuid(), Guid.NewGuid(), "Name", "Description",
                                                  0.12m, DateTime.Now, Period.Create(DateTime.Now, DateTime.Now));
            var repository = new Mock <IExpenseRepository>();

            repository.Setup(
                e => e.GetByIdAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(entity);
            ModifyExpenseCommand cmd =
                new ModifyExpenseCommand(expectedId, Guid.NewGuid(), expectedName, "Description",
                                         0.12m, DateTime.Now, DateTime.Now, DateTime.Now, 1);

            ExpenseCommandHandler actual = new ExpenseCommandHandler(repository.Object);

            // Act
            await actual.HandleAsync(cmd);

            // Assert
            Assert.IsTrue(entity.Id == expectedId);
            Assert.IsTrue(entity.Name == expectedName);
        }
        public void ShouldCreateInvalidDiscountCupon()
        {
            var discountCupon = new DiscountCupon("XPTO", 10, Period.Create(new DateTime(2008, 12, 25), new DateTime(2008, 12, 26)));

            Assert.AreEqual(false, discountCupon.IsValid());
        }
Exemple #21
0
 public void GivenUnePeriodeEstCreee()
 {
     _period = Period.Create(PeriodName.From(3, 2019));
 }
Exemple #22
0
 public Period Create(DateTime start, DateTime end) => Period.Create(start, end);
Exemple #23
0
        public void ShouldHaveDeletedEvent()
        {
            // Arrange
            Guid expectedId = Guid.NewGuid();

            Expense actual = Expense.Create(expectedId, Guid.NewGuid(), Guid.NewGuid(),
                                            "Name", "Description", 100.12M, DateTime.Now, Period.Create(DateTime.Now, DateTime.Now));

            actual.FlushUncommitedEvents();

            // Act
            actual.Delete();

            // Assert
            Assert.IsTrue(actual.Events != null);
            Assert.IsTrue(actual.Events.Count == 1);
            var events = actual.FlushUncommitedEvents();

            Assert.IsTrue(events != null);
            Assert.IsTrue(events.Length == 1);
            Assert.IsTrue(events[0] is ExpenseDeletedEvent);
            ExpenseDeletedEvent @event = events[0] as ExpenseDeletedEvent;

            Assert.IsTrue(@event.EntityId == expectedId);
        }
        public async Task HandleAsync(CreateExpenseCommand message, CancellationToken token = default(CancellationToken))
        {
            var expense = Expense.Create(message.ExpenseId, message.HouseholdId, message.ExpenseTypeId, message.Name,
                                         message.Description, message.Amount, message.Date, Period.Create(message.PeriodStart, message.PeriodEnd));

            _expenses.Add(expense);
            await _expenses.SaveChangesAsync(token);
        }