Beispiel #1
0
 public Task Create(CreateServiceCommand command)
 {
     Name   = command.Name;
     Url    = command.Url;
     Status = Status.Closed;
     return(Task.CompletedTask);
 }
Beispiel #2
0
        public async Task ShouldDeleteService()
        {
            var categoryIds = await AddCategories();

            var createCommand = new CreateServiceCommand
            {
                Address            = "Address",
                ContactEmail       = "*****@*****.**",
                ContactPhoneNumber = "099123456",
                Description        = "Description",
                Name         = "New Service",
                ServicePrice = "0",
                CategoryIds  = categoryIds.Select(s => s.ToString()).ToArray()
            };

            var serviceId = await SendAsync(createCommand);

            var getServicesCommand = new GetAllServicesQuery();

            var services = await SendAsync(getServicesCommand);

            services.Should().HaveCount(1);

            var deleteCommand = new DeleteServiceCommand {
                Id = serviceId
            };

            await SendAsync(deleteCommand);

            var getServices = new GetAllServicesQuery();

            var result = await SendAsync(getServices);

            result.Should().HaveCount(0);
        }
Beispiel #3
0
        public void CreateService_Should_Add_ToServiceRepository()
        {
            // Arrange
            var serviceFactoryMock = new Mock <IServiceFactory>();
            var serviceRepoMock    = new Mock <IServiceRepository>();
            var userMock           = new Mock <IUserRepository>();
            var writerMock         = new Mock <IWriter>();

            var sut = new CreateServiceCommand(serviceFactoryMock.Object, serviceRepoMock.Object, writerMock.Object);
            //
            var list = new List <IService>();

            serviceRepoMock.SetupGet(x => x.Services).Returns(list);

            serviceFactoryMock.Setup(x => x.CreateService(It.IsAny <string>(), It.IsAny <decimal>())).Verifiable();


            // var serviceFactoryMock = new Mock<IServiceFactory>();
            var parameters = new List <string>()
            {
                "",
                "Name",
                "7"
            };

            sut.Parameters = parameters;
            // Act

            sut.Execute();


            serviceRepoMock.Verify(x => x.Services, Times.Once());

            // Assert);
        }
Beispiel #4
0
        void PupulateEntities(out int clientId, out int serviceId)
        {
            var createCategory = new AddCategoryCommand(null, "test");

            ExecuteCommand(createCategory);

            var createClientCommand = new CreateClientCommand("test", "*****@*****.**", "123456", "brag", 23.565, 12.34, 1);

            ExecuteCommand(createClientCommand);

            var category = Session.QueryOver <Category>().FutureValue();
            var client   = Session.QueryOver <Client>().FutureValue();

            var categoryId = category.Value.Id;

            clientId = client.Value.Id;

            var createServiceCommand = new CreateServiceCommand(true, "title", "body", categoryId, clientId, 23.234, 5.343, null, null, null);

            ExecuteCommand(createServiceCommand);

            var service = Session.QueryOver <Service>().SingleOrDefault();

            serviceId = service.Id;
        }
Beispiel #5
0
        public async Task ShouldCreateService()
        {
            var categoryIds = await AddCategories();

            var command = new CreateServiceCommand
            {
                Address            = "Address",
                ContactEmail       = "*****@*****.**",
                ContactPhoneNumber = "099123456",
                Description        = "Description",
                Name         = "New Service",
                ServicePrice = "0",
                CategoryIds  = categoryIds.Select(s => s.ToString()).ToArray()
            };

            var serviceId = await SendAsync(command);

            var service = await FindAsync <Service>(serviceId);

            service.Should().NotBeNull();
            service.Address.Should().Be("Address");
            service.ContactEmail.Should().Be("*****@*****.**");
            service.Description.Should().Be("Description");
            service.Name.Should().Be("New Service");
            service.ServicePrice.Should().Be("0");
        }
Beispiel #6
0
        public async Task <IActionResult> CreateService(CreateServiceCommand command)
        {
            ServiceView s = await mediator.Dispatch <CreateServiceCommand, ServiceView>(
                command,
                User.GetUserId()
                );

            return(Ok(s));
        }
Beispiel #7
0
        public async Task <IActionResult> Add(ServiceDTO serviceDTO)
        {
            var createServiceCommand = new CreateServiceCommand();

            createServiceCommand.ServiceDTO = serviceDTO;
            int result = await Mediator.Send(createServiceCommand);

            return(RedirectToAction("List"));
        }
        public Service Create(CreateServiceCommand command)
        {
            var service = new Service(command.Name, command.Value, command.CoachingProcess, command.Description);
            service.Validate();
            _repository.Create(service);

            if (Commit())
                return service;

            return null;
        }
Beispiel #9
0
        public async Task <IActionResult> Post([FromBody] CreateServiceRequest request)
        {
            var command = new CreateServiceCommand(request.Name, request.AllowHalfTime);
            var result  = await createServiceService.Process(command);

            return(Ok(new ApiReturnItem <ServiceResult>
            {
                Item = result,
                Success = true
            }));
        }
Beispiel #10
0
        private static ICommand GetServiceCommand()
        {
            var serviceFactoryMock = new Mock <IServiceFactory>();
            var serviceRepoMock    = new Mock <IServiceRepository>();
            var userMock           = new Mock <IUserRepository>();
            var writerMock         = new Mock <IWriter>();

            var sut = new CreateServiceCommand(serviceFactoryMock.Object, serviceRepoMock.Object, writerMock.Object);


            return(sut);
        }
        public async Task <IActionResult> CreateService([FromBody] CreateServiceCommand command)
        {
            try
            {
                var result = await _mediator.Send(command);

                return(Ok(result));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public Service Create(CreateServiceCommand command)
        {
            var service = new Service(command.Name, command.Value, command.CoachingProcess, command.Description);

            service.Validate();
            _repository.Create(service);

            if (Commit())
            {
                return(service);
            }

            return(null);
        }
Beispiel #13
0
        public IResult Handler(CreateServiceCommand command)
        {
            var service = new Service(command.Name, command.Description, command.Price);

            AddNotifications(service);

            if (service.Invalid)
            {
                return(new CommandResult(false, "Dados inválidos", null, Notifications));
            }

            var serviceCreated = _repository.Save(service);

            return(new CommandResult(true, "Dados salvo com sucesso", new ServiceCreatedViewModel(serviceCreated.Id, service.Name), Notifications));
        }
        public Task<HttpResponseMessage> Post([FromBody]dynamic body)
        {
            var service = _service.GetOneByName((string)body.name);
            if (service != null)
                return CreateResponse(HttpStatusCode.Ambiguous, service);

            var commandService = new CreateServiceCommand(
                   name: (string)body.name,
                   value: (float)body.value,
                   description: (string)body.description
               );

            service = _service.Create(commandService);

            return CreateResponse(HttpStatusCode.Created, service);
        }
        public async Task <IActionResult> AddService([FromBody] List <AddServicesRequest> request)
        {
            try
            {
                foreach (var item in request)
                {
                    var createServiceCommand = new CreateServiceCommand(item);
                    var result = await mediator.Send(createServiceCommand);
                }
            }
            catch (Exception ex)
            {
                return(NotFound(ex));
            }

            return(StatusCode(201));
        }
        public void Create_ServiceRequest_With_All_Required_Information()
        {
            var initialCount = Session.QueryOver<ServiceOffering>().RowCount();
            int categoryId, clientId;
            PupulateEntities(out categoryId, out clientId);

            var command = new CreateServiceCommand(false, "title", "body", categoryId, clientId, 23.234, 5.343, null, null, null);
            ExecuteCommand(command);

            var service = Session.QueryOver<ServiceRequest>()
                .Where(s => s.Category.Id == categoryId && s.Client.Id == clientId)
                .And(s => s.Title == "title" && s.Body == "body")
                .SingleOrDefault();

            Assert.NotNull(service);
            Assert.AreEqual(0, initialCount);
        }
        public Task <HttpResponseMessage> Post([FromBody] dynamic body)
        {
            var service = _service.GetOneByName((string)body.name);

            if (service != null)
            {
                return(CreateResponse(HttpStatusCode.Ambiguous, service));
            }

            var commandService = new CreateServiceCommand(
                name: (string)body.name,
                value: (float)body.value,
                description: (string)body.description
                );

            service = _service.Create(commandService);

            return(CreateResponse(HttpStatusCode.Created, service));
        }
        public void Create_ServiceRequest_With_All_Required_Information()
        {
            var initialCount = Session.QueryOver <ServiceOffering>().RowCount();
            int categoryId, clientId;

            PupulateEntities(out categoryId, out clientId);

            var command = new CreateServiceCommand(false, "title", "body", categoryId, clientId, 23.234, 5.343, null, null, null);

            ExecuteCommand(command);

            var service = Session.QueryOver <ServiceRequest>()
                          .Where(s => s.Category.Id == categoryId && s.Client.Id == clientId)
                          .And(s => s.Title == "title" && s.Body == "body")
                          .SingleOrDefault();

            Assert.NotNull(service);
            Assert.AreEqual(0, initialCount);
        }
        void PupulateEntities(out int clientId, out int serviceId)
        {
            var createCategory = new AddCategoryCommand(null, "test");
            ExecuteCommand(createCategory);

            var createClientCommand = new CreateClientCommand("test", "*****@*****.**", "123456", "brag", 23.565, 12.34, 1);
            ExecuteCommand(createClientCommand);

            var category = Session.QueryOver<Category>().FutureValue();
            var client = Session.QueryOver<Client>().FutureValue();

            var categoryId = category.Value.Id;
            clientId = client.Value.Id;

            var createServiceCommand = new CreateServiceCommand(true, "title", "body", categoryId, clientId, 23.234, 5.343, null, null, null);
            ExecuteCommand(createServiceCommand);

            var service =  Session.QueryOver<Service>().SingleOrDefault();

            serviceId = service.Id;
        }
        public ActionResult Create(CreateServiceModel createServiceModel)
        {
            if (ModelState.IsValid)
            {
                FileBase image = createServiceModel.Image != null ? new FileBaseAdapter(createServiceModel.Image) : null;

                var isServiceOffering = createServiceModel.Type == 1;
                var command           = new CreateServiceCommand(isServiceOffering, createServiceModel.Title, createServiceModel.Body,
                                                                 createServiceModel.CategoryId, UserInfo.Id, createServiceModel.Latitude,
                                                                 createServiceModel.Longitude, null, _fileSystem, image);
                ExecuteCommand(command);

                TempData[ViewDataKeys.Message] = new SuccessMessage(string.Format(Resources.EntityCreateSuccess, "Service"));

                return(RedirectToAction("Profile", "Accounts"));
            }

            ViewData[ViewDataKeys.Categories]   = GetCategories();
            ViewData[ViewDataKeys.ServiceTypes] = GetServiceTypes();

            return(View());
        }
        public async Task ShouldUpdateService()
        {
            var categoryIds = await AddCategories();

            var createCommand = new CreateServiceCommand
            {
                Address            = "Address",
                ContactEmail       = "*****@*****.**",
                ContactPhoneNumber = "099123456",
                Description        = "Description",
                Name         = "New Service",
                ServicePrice = "0",
                CategoryIds  = categoryIds.Select(s => s.ToString()).ToArray()
            };

            var serviceId = await SendAsync(createCommand);

            var updateCommand = new UpdateServiceCommand {
                Id                 = serviceId.ToString(),
                Address            = "New address",
                ContactEmail       = "*****@*****.**",
                ContactPhoneNumber = "099123456",
                Description        = "Description",
                Name               = "New Service",
                ServicePrice       = "0",
                CategoryIds        = categoryIds.Select(s => s.ToString()).ToArray()
            };

            await SendAsync(updateCommand);

            var getServicesQuery = new GetServiceQuery
            {
                ServiceId = serviceId
            };

            var result = await SendAsync(getServicesQuery);

            result.Address.Should().Be("New address");
        }
Beispiel #22
0
        public void CreateService_Should_Throw_ArgumentException_WhenIsAddedExistingService()
        {
            // Arrange
            var serviceFactoryMock = new Mock <IServiceFactory>();
            var serviceRepoMock    = new Mock <IServiceRepository>();
            var userMock           = new Mock <IUserRepository>();
            var writerMock         = new Mock <IWriter>();

            var sut = new CreateServiceCommand(serviceFactoryMock.Object, serviceRepoMock.Object, writerMock.Object);
            //
            var list = new List <IService>();

            var serviceMock = new Mock <IService>();

            serviceMock.SetupGet(x => x.Name).Returns("Name");

            list.Add(serviceMock.Object);

            serviceRepoMock.SetupGet(x => x.Services).Returns(list);
            serviceFactoryMock.Setup(x => x.CreateService(It.IsAny <string>(), It.IsAny <decimal>())).Verifiable();


            // var serviceFactoryMock = new Mock<IServiceFactory>();
            var parameters = new List <string>()
            {
                "",
                "Name",
                "7"
            };

            sut.Parameters = parameters;

            // Act & Assert
            //serviceRepoMock.Verify(x => x.Services, Times.Once());


            Assert.ThrowsException <ArgumentException>(() => sut.Execute());
        }
Beispiel #23
0
        public async Task <IActionResult> Create(CreateServiceCommand command)
        {
            var serviceId = await Mediator.Send(command);

            return(Ok(serviceId));
        }
Beispiel #24
0
        public async Task <IActionResult> Add([FromBody] CreateServiceCommand command)
        {
            var result = await Mediator.Send(command);

            return(Ok(result));
        }
        public ActionResult Create(CreateServiceModel createServiceModel)
        {
            if (ModelState.IsValid)
            {
                FileBase image = createServiceModel.Image != null ? new FileBaseAdapter(createServiceModel.Image) : null;

                var isServiceOffering = createServiceModel.Type == 1;
                var command = new CreateServiceCommand(isServiceOffering, createServiceModel.Title, createServiceModel.Body,
                                                       createServiceModel.CategoryId, UserInfo.Id, createServiceModel.Latitude,
                                                       createServiceModel.Longitude, null, _fileSystem, image);
                ExecuteCommand(command);

                TempData[ViewDataKeys.Message] = new SuccessMessage(string.Format(Resources.EntityCreateSuccess, "Service"));

                return RedirectToAction("Profile", "Accounts");
            }

            ViewData[ViewDataKeys.Categories] = GetCategories();
            ViewData[ViewDataKeys.ServiceTypes] = GetServiceTypes();

            return View();
        }
Beispiel #26
0
 public async Task CreateService([FromServices] CreateServiceCommand command, [FromBody] ServiceInput input)
 {
     await command.Execute(input);
 }
Beispiel #27
0
 public IActionResult New([FromBody] CreateServiceCommand service)
 {
     return Ok(_handler.Handler(service));
 }
        public async Task <ActionResult> Create([FromForm] CreateServiceCommand command)
        {
            await Mediator.Send(command);

            return(NoContent());
        }
 public async Task <ActionResult <int> > Create(CreateServiceCommand command)
 {
     return(await Mediator.Send(command));
 }
Beispiel #30
0
 public CreateServiceCommandValidatorTests()
 {
     this.createValidator = new CreateServiceCommandValidator();
     this.createCommand   = new CreateServiceCommand();
 }