コード例 #1
0
        public void ShouldReturnExpectedResult(int capacity, bool isSuccess)
        {
            var capacityResult = Capacity.Create(capacity);

            capacityResult.IsSuccess.Should().Be(isSuccess);

            if (isSuccess)
            {
                capacityResult.Value.Value.Should().Be(capacity);
            }
        }
コード例 #2
0
        public static Result <EditExamCommand> Create(long examId, EditExamRequest request, IExamExistenceValidator examExistenceValidator)
        {
            var id       = ExamId.Create(examId, examExistenceValidator);
            var capacity = Capacity.Create(request.Capacity)
                           .BindErrorsTo(nameof(request.Capacity));
            var registrationStartDate = UtcDate.Create(request.RegistrationStartDate)
                                        .BindErrorsTo(nameof(request.RegistrationStartDate));
            var registrationEndDate = UtcDate.Create(request.RegistrationEndDate)
                                      .BindErrorsTo(nameof(request.RegistrationEndDate));

            return(Result.Combine(id, capacity, registrationStartDate, registrationEndDate)
                   .OnSuccess(() => new EditExamCommand(id.Value, capacity.Value, registrationStartDate.Value, registrationEndDate.Value)));
        }
コード例 #3
0
        public void SetUp()
        {
            _subjectId  = ValueObjectProvider.GetSubjectId(10);
            _locationId = ValueObjectProvider.GetLocationId(11);
            _capacity   = Capacity.Create(15).Value;

            _systemTimeProvider = new Mock <ISystemTimeProvider>();
            _systemTimeProvider.Setup(provider => provider.UtcNow)
            .Returns(new DateTime(2020, 02, 01, 00, 00, 00, DateTimeKind.Utc));

            _examRepository = new Mock <IExamRepository>();
            _examRepository.Setup(repository => repository.SaveAsync(It.IsAny <Exam>()))
            .Returns <Exam>(exam => Task.FromResult(Result.Ok(exam)));
        }
コード例 #4
0
        public static Result <CreateExamCommand> Create(CreateExamRequest request,
                                                        ISubjectExistenceValidator subjectExistenceValidator,
                                                        ILocationExistenceValidator locationExistenceValidator)
        {
            var subjectId = SubjectId.Create(request.SubjectId, subjectExistenceValidator)
                            .BindErrorsTo(nameof(request.SubjectId));
            var locationId = LocationId.Create(request.LocationId, locationExistenceValidator)
                             .BindErrorsTo(nameof(request.LocationId));
            var examDateTime = UtcDateTime.Create(request.ExamDateTime)
                               .BindErrorsTo(nameof(request.ExamDateTime));
            var capacity = Capacity.Create(request.Capacity)
                           .BindErrorsTo(nameof(request.Capacity));
            var registrationStartDate = UtcDate.Create(request.RegistrationStartDate)
                                        .BindErrorsTo(nameof(request.RegistrationStartDate));
            var registrationEndDate = UtcDate.Create(request.RegistrationEndDate)
                                      .BindErrorsTo(nameof(request.RegistrationEndDate));

            return(Result.Combine(subjectId, locationId, examDateTime, capacity, registrationStartDate,
                                  registrationEndDate)
                   .OnSuccess(() => new CreateExamCommand(subjectId.Value, locationId.Value, examDateTime.Value,
                                                          capacity.Value, registrationStartDate.Value, registrationEndDate.Value)));
        }