Example #1
0
        public async Task ShouldRequireFutureDateAsync()
        {
            var userId = await RunAsDefaultUserAsync();

            var command = new CreateFormCommand
            {
                Name        = "Urim",
                Company     = "Google",
                Email       = "*****@*****.**",
                Telephone   = "+38349123456",
                Appointment = DateTime.UtcNow.AddDays(-1),
            };

            FluentActions.Invoking(async() => {
                await SendAsync(command);
            }).Should().Throw <ValidationException>();

            command.Appointment = DateTime.UtcNow.AddMinutes(80);

            var id = await SendAsync(command);

            id.Should <Guid>();
            id.Should().NotBe(Guid.Empty);

            Form form = await FindAsync <Form>(id);

            form.Should().NotBeNull();
            form.Name.Should().Be(command.Name);
            form.Telephone.Should().Be(command.Telephone);
            form.Appointment.Should().Be(command.Appointment);
            form.Email.Should().Be(command.Email);
            form.Date.Should().BeCloseTo(DateTime.Now, 10000);
        }
Example #2
0
        //[TestCase("asd", ExpectedResult = typeof(ValidationException))]
        public async Task ShouldRequireValidPhoneNumberAsync(string number)
        {
            var userId = await RunAsDefaultUserAsync();

            var command = new CreateFormCommand
            {
                Name        = "Urim",
                Company     = "Google",
                Email       = "*****@*****.**",
                Telephone   = number,
                Appointment = DateTime.UtcNow.AddDays(1),
            };

            var id = await SendAsync(command);

            id.Should <Guid>();
            id.Should().NotBe(Guid.Empty);

            Form form = await FindAsync <Form>(id);

            form.Should().NotBeNull();
            form.Name.Should().Be(command.Name);
            form.Telephone.Should().Be(command.Telephone);
            form.Appointment.Should().Be(command.Appointment);
            form.Email.Should().Be(command.Email);
            form.Date.Should().BeCloseTo(DateTime.Now, 10000);
        }
Example #3
0
        public void ShouldRequireAllFields()
        {
            var command = new CreateFormCommand
            {
                Name = "Urim"
            };

            FluentActions.Invoking(async() => {
                await SendAsync(command);
            }).Should().Throw <ValidationException>();
        }
Example #4
0
        public async Task <IActionResult> PostForm([FromBody] CreateFormCommand form)
        {
            Guid guid = await Mediator.Send(form);

            return(CreatedAtAction("GetForm", new { id = guid }, form));
        }
Example #5
0
 public async Task <ApiResult> CreateForm([FromBody] CreateFormCommand command)
 {
     return(await _sender.Send(command));
 }