コード例 #1
0
 public static ApplicationCreateDto ToApplicationCreateDto(this ApplicationCreateModel applicationCreateModel)
 {
     return(ObjectMapperManager
            .DefaultInstance
            .GetMapper <ApplicationCreateModel, ApplicationCreateDto>()
            .Map(applicationCreateModel));
 }
コード例 #2
0
        public async Task WhenRegisteringExistingApplicationThenErrorShouldBeRaised()
        {
            using (IDependencyResolver resolver = DependencyResolverFactory.CreateDependencyResolver())
            {
                LoggerController controller = new LoggerController(resolver.Resolve <IApplicationService>(),
                                                                   resolver.Resolve <ILogService>());

                string displayName = GenerateDisplayName();

                ApplicationCreateModel applicationCreateModel = new ApplicationCreateModel()
                {
                    DisplayName = displayName,
                    Password    = "******"
                };

                OkNegotiatedContentResult <int> result = await controller.RegisterAsync(applicationCreateModel) as OkNegotiatedContentResult <int>;

                Assert.IsNotNull(result);

                BadRequestErrorMessageResult newResult = await controller.RegisterAsync(applicationCreateModel) as BadRequestErrorMessageResult;

                Assert.IsNotNull(newResult);
                Assert.AreEqual(newResult.Message, $"Application with DisplayName {displayName} already exists.");
            }
        }
コード例 #3
0
        public async Task WhenRegisteringApplicationThenApplicationIsRegistered()
        {
            using (IDependencyResolver resolver = DependencyResolverFactory.CreateDependencyResolver())
            {
                LoggerController controller = new LoggerController(resolver.Resolve <IApplicationService>(), resolver.Resolve <ILogService>());

                ApplicationCreateModel applicationCreateModel = new ApplicationCreateModel()
                {
                    DisplayName = GenerateDisplayName(),
                    Password    = "******"
                };

                OkNegotiatedContentResult <int> result = await controller.RegisterAsync(applicationCreateModel) as OkNegotiatedContentResult <int>;

                Assert.IsNotNull(result);
            }
        }
コード例 #4
0
        public async Task <IHttpActionResult> RegisterAsync(ApplicationCreateModel applicationCreateModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                ApplicationCreateDto applicationCreateDto = applicationCreateModel.ToApplicationCreateDto();

                int applicationId = await _applicationService.AddApplicationAsync(applicationCreateDto);

                return(Ok(applicationId));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #5
0
        public IHttpActionResult CreateApplication(ApplicationCreateModel app)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            ApplicationDTO newApp = new ApplicationDTO()
            {
                ApplicationName = app.ApplicationName,
                UserOwnerId     = app.UserOwnerId
            };

            try
            {
                ApplicationsService.Create(newApp);
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
            return(CreatedAtRoute("DefaultApi", new { id = newApp.Id }, newApp));
        }