コード例 #1
0
        public void ProfileShouldBeOptional()
        {
            var vendor = new Vendor
            {
                VendorNamespacePrefixes = new List <VendorNamespacePrefix> {
                    new VendorNamespacePrefix {
                        NamespacePrefix = "http://tests.com"
                    }
                },
                VendorName = "Integration Tests"
            };

            var user = new Admin.DataAccess.Models.User
            {
                Email    = "*****@*****.**",
                FullName = "Integration Tests",
                Vendor   = vendor
            };

            Save(vendor, user);

            AddApplicationResult result = null;

            Scoped <IUsersContext>(usersContext =>
            {
                var command        = new AddApplicationCommand(usersContext, new InstanceContext());
                var newApplication = new TestApplication
                {
                    ApplicationName          = "Test Application",
                    ClaimSetName             = "FakeClaimSet",
                    ProfileId                = null,
                    VendorId                 = vendor.VendorId,
                    EducationOrganizationIds = new List <int> {
                        12345, 67890
                    }
                };

                result = command.Execute(newApplication);
            });

            Transaction(usersContext =>
            {
                var persistedApplication = usersContext.Applications.Single(a => a.ApplicationId == result.ApplicationId);

                persistedApplication.ClaimSetName.ShouldBe("FakeClaimSet");
                persistedApplication.Profiles.Count.ShouldBe(0);
                persistedApplication.ApplicationEducationOrganizations.Count.ShouldBe(2);
                persistedApplication.ApplicationEducationOrganizations.All(o => o.EducationOrganizationId == 12345 || o.EducationOrganizationId == 67890).ShouldBeTrue();

                persistedApplication.Vendor.VendorId.ShouldBeGreaterThan(0);
                persistedApplication.Vendor.VendorId.ShouldBe(vendor.VendorId);

                persistedApplication.ApiClients.Count.ShouldBe(1);
                var apiClient = persistedApplication.ApiClients.First();
                apiClient.Name.ShouldBe("Test Application");
                apiClient.ApplicationEducationOrganizations.All(o => o.EducationOrganizationId == 12345 || o.EducationOrganizationId == 67890).ShouldBeTrue();
                apiClient.Key.ShouldBe(result.Key);
                apiClient.Secret.ShouldBe(result.Secret);
            });
        }
        public void ShouldFailForInvalidVendor()
        {
            var vendor = new Vendor
            {
                VendorNamespacePrefixes = new List <VendorNamespacePrefix> {
                    new VendorNamespacePrefix {
                        NamespacePrefix = "http://tests.com"
                    }
                },
                VendorName = "Integration Tests"
            };

            var user = new Admin.DataAccess.Models.User
            {
                Email    = "*****@*****.**",
                FullName = "Integration Tests",
                Vendor   = vendor
            };

            Save(vendor, user);

            var command        = new AddApplicationCommand(SetupContext, new InstanceContext());
            var newApplication = new TestApplication
            {
                Environment     = CloudOdsEnvironment.Production,
                ApplicationName = "Production-Test Application",
                ClaimSetName    = "FakeClaimSet",
                ProfileId       = 0,
                VendorId        = 0
            };

            Assert.Throws <InvalidOperationException>(() => command.Execute(newApplication));
        }
コード例 #3
0
 public AddAppViewModel(MainPageViewModel viewModel)
 {
     MainPageViewModel          = viewModel;
     AddApplicationCommand      = new AddApplicationCommand(this);
     DeleteApplicationCommand   = new DeleteApplicationCommand(this);
     DeployAsiLoaderCommand     = new DeployAsiLoaderCommand(this);
     SetApplicationImageCommand = new SetApplicationImageCommand(this);
 }
コード例 #4
0
        public IActionResult AddApplication(AddApplicationCommand command)
        {
            if (string.IsNullOrEmpty(command.Currency) ||
                string.IsNullOrEmpty(command.ClientId) ||
                string.IsNullOrEmpty(command.DepartmentAddress) ||
                command.Amount == 0)
            {
                _logger.LogError("Request is invalid");
                return(BadRequest());
            }

            _logger.LogInformation($"Processing request: {JsonConvert.SerializeObject(command)}");

            _channel.QueueDeclare(queue: AddQueueName,
                                  durable: false,
                                  exclusive: false,
                                  autoDelete: false,
                                  arguments: null);

            var mqCommand = new AddApplicationMqCommand
            {
                ClientId          = command.ClientId,
                Amount            = command.Amount,
                Currency          = command.Currency,
                DepartmentAddress = command.DepartmentAddress,
                ClientIp          = HttpContext.Connection.RemoteIpAddress.ToString(),
            };

            string message;

            try
            {
                message = JsonConvert.SerializeObject(mqCommand);
                var body = Encoding.UTF8.GetBytes(message);

                _channel.BasicPublish(exchange: "",
                                      routingKey: AddQueueName,
                                      basicProperties: _props,
                                      body: body);
            }
            catch (Exception e)
            {
                _logger.LogError($"Error from message queue: {e.Message}");
                return(StatusCode((int)HttpStatusCode.BadGateway));
            }

            _logger.LogInformation($"Sent message: {message}");

            _channel.BasicConsume(
                consumer: _consumer,
                queue: _replyQueueName,
                autoAck: true);

            var response = _respQueue.Take();

            _logger.LogInformation($"Received message from server: {response}");
            return(Ok(response));
        }
        public void ShouldExecute()
        {
            const string odsInstanceName = "Test Instance";
            var          vendor          = new Vendor
            {
                VendorNamespacePrefixes = new List <VendorNamespacePrefix> {
                    new VendorNamespacePrefix {
                        NamespacePrefix = "http://tests.com"
                    }
                },
                VendorName = "Integration Tests"
            };

            var user = new Admin.DataAccess.Models.User
            {
                Email    = "*****@*****.**",
                FullName = "Integration Tests",
                Vendor   = vendor
            };

            var profile = new Profile
            {
                ProfileName = "Test Profile"
            };

            var odsInstance = new OdsInstance
            {
                Name         = odsInstanceName,
                InstanceType = "Ods",
                IsExtended   = false,
                Status       = "OK",
                Version      = "1.0.0"
            };

            Save(vendor, user, profile, odsInstance);

            var instanceContext = new InstanceContext
            {
                Id   = 1,
                Name = odsInstanceName
            };

            var command        = new AddApplicationCommand(SetupContext, instanceContext);
            var newApplication = new TestApplication
            {
                Environment              = CloudOdsEnvironment.Production,
                ApplicationName          = "Test Application",
                ClaimSetName             = "FakeClaimSet",
                ProfileId                = profile.ProfileId,
                VendorId                 = vendor.VendorId,
                EducationOrganizationIds = new List <int> {
                    12345, 67890
                }
            };

            var result = command.Execute(newApplication);

            var persistedApplication = TestContext.Applications.Single(a => a.ApplicationId == result.ApplicationId);

            persistedApplication.ClaimSetName.ShouldBe("FakeClaimSet");
            persistedApplication.Profiles.Count.ShouldBe(1);
            persistedApplication.Profiles.First().ProfileName.ShouldBe("Test Profile");
            persistedApplication.ApplicationEducationOrganizations.Count.ShouldBe(2);
            persistedApplication.ApplicationEducationOrganizations.All(o => o.EducationOrganizationId == 12345 || o.EducationOrganizationId == 67890).ShouldBeTrue();

            persistedApplication.Vendor.VendorId.ShouldBeGreaterThan(0);
            persistedApplication.Vendor.VendorId.ShouldBe(vendor.VendorId);

            persistedApplication.ApiClients.Count.ShouldBe(1);
            var apiClient = persistedApplication.ApiClients.First();

            apiClient.Name.ShouldBe(CloudOdsApplicationName.GetPersistedName("Test Application", CloudOdsEnvironment.Production));
            apiClient.ApplicationEducationOrganizations.All(o => o.EducationOrganizationId == 12345 || o.EducationOrganizationId == 67890).ShouldBeTrue();
            apiClient.Key.ShouldBe(result.Key);
            apiClient.Secret.ShouldBe(result.Secret);

            persistedApplication.OdsInstance.ShouldNotBeNull();
            persistedApplication.OdsInstance.Name.ShouldBe(odsInstanceName);
        }
コード例 #6
0
        private ApiClient SetupApplicationForInstance(OdsInstance instance)
        {
            var vendor = new Vendor
            {
                VendorNamespacePrefixes = new List <VendorNamespacePrefix> {
                    new VendorNamespacePrefix {
                        NamespacePrefix = "http://tests.com"
                    }
                },
                VendorName = "Integration Tests"
            };

            var user = new Admin.DataAccess.Models.User
            {
                Email    = "*****@*****.**",
                FullName = "Integration Tests",
                Vendor   = vendor
            };

            var profile = new Profile
            {
                ProfileName = "Test Profile"
            };

            Save(vendor, user, profile, instance);

            var instanceContext = new InstanceContext
            {
                Id   = instance.OdsInstanceId,
                Name = instance.Name
            };

            AddApplicationResult result = null;

            Scoped <IUsersContext>(usersContext =>
            {
                var command        = new AddApplicationCommand(usersContext, instanceContext);
                var newApplication = new TestApplication
                {
                    ApplicationName          = "Test Application",
                    ClaimSetName             = "FakeClaimSet",
                    ProfileId                = profile.ProfileId,
                    VendorId                 = vendor.VendorId,
                    EducationOrganizationIds = new List <int> {
                        12345, 67890
                    }
                };
                result = command.Execute(newApplication);
            });

            ApiClient apiClient = null;

            Scoped <IUsersContext>(usersContext =>
            {
                var persistedApplication = usersContext.Applications.Single(a => a.ApplicationId == result.ApplicationId);
                persistedApplication.ApiClients.Count.ShouldBe(1);

                apiClient = persistedApplication.ApiClients.First();
                apiClient.Name.ShouldBe("Test Application");
                apiClient.ApplicationEducationOrganizations.All(o => o.EducationOrganizationId == 12345 || o.EducationOrganizationId == 67890).ShouldBeTrue();
                apiClient.Key.ShouldBe(result.Key);
                apiClient.Secret.ShouldBe(result.Secret);

                persistedApplication.OdsInstance.ShouldNotBeNull();
                persistedApplication.OdsInstance.Name.ShouldBe(instance.Name);
            });

            return(apiClient);
        }
コード例 #7
0
 /// <inheritdoc />
 public AddApplicationViewModel(FirstLaunchViewModel firstLaunchViewModel, AddApplicationCommand addApplicationCommand)
 {
     FirstLaunchViewModel  = firstLaunchViewModel;
     AddApplicationCommand = addApplicationCommand;
 }