Ejemplo n.º 1
0
        public async Task InstallationSiteModel_Save_DoesSave()
        {
            // Arrange
            Installation installation = new Installation {
                CreatedAt = DateTime.Now, Name = Guid.NewGuid().ToString()
            };

            await installation.Create(DbContext);

            Random rnd = new Random();

            InstallationSite installationSite = new InstallationSite
            {
                InstallationId = installation.Id, SDKSiteId = rnd.Next(1, 255)
            };

            // Act
            await installationSite.Create(DbContext);

            InstallationSite               dbInstallationSite       = DbContext.InstallationSites.AsNoTracking().First();
            List <InstallationSite>        installationSiteList     = DbContext.InstallationSites.AsNoTracking().ToList();
            List <InstallationSiteVersion> installationSiteVersions = DbContext.InstallationSiteVersions.AsNoTracking().ToList();

            // Assert
            Assert.NotNull(dbInstallationSite);

            Assert.AreEqual(1, installationSiteList.Count());
            Assert.AreEqual(1, installationSiteVersions.Count());

            Assert.AreEqual(installationSite.CreatedAt.ToString(), dbInstallationSite.CreatedAt.ToString());
            Assert.AreEqual(installationSite.InstallationId, dbInstallationSite.InstallationId);
        }
Ejemplo n.º 2
0
        public async Task <OperationResult> Update(InstallationModel updateModel)
        {
            var installation =
                await _dbContext.Installations.SingleOrDefaultAsync(x => x.Id == updateModel.Id);

            if (installation != null)
            {
                installation.Name = updateModel.Name;
                await installation.Update(_dbContext);

                var installationSites            = installation.InstallationSites;
                var toBeRemovedInstallationSites = installationSites;

                foreach (var deployedCheckbox in updateModel.DeployCheckboxes)
                {
                    var installationSite =
                        installationSites.SingleOrDefault(x => x.SDKSiteId == deployedCheckbox.Id);
                    if (installationSite == null)
                    {
                        installationSite = new InstallationSite
                        {
                            InstallationId = installation.Id,
                            SDKSiteId      = deployedCheckbox.Id
                        };
                        await installationSite.Create(_dbContext);
                    }
                    else
                    {
                        if (installationSite.WorkflowState == Constants.WorkflowStates.Removed)
                        {
                            installationSite.WorkflowState = Constants.WorkflowStates.Created;
                            await installationSite.Update(_dbContext);
                        }
                        toBeRemovedInstallationSites.Remove(installationSite);
                    }
                }

                foreach (var installationSite in toBeRemovedInstallationSites)
                {
                    await installationSite.Delete(_dbContext);
                }
                return(new OperationResult(true));
            }
            return(new OperationResult(false));
        }
Ejemplo n.º 3
0
        public async Task <OperationResult> Create(InstallationModel createModel)
        {
            var installation = new Installation
            {
                Name = createModel.Name
            };
            await installation.Create(_dbContext);

            foreach (var deployedCheckbox in createModel.DeployCheckboxes)
            {
                if (deployedCheckbox.IsChecked)
                {
                    var installationSite = new InstallationSite
                    {
                        InstallationId = installation.Id,
                        SDKSiteId      = deployedCheckbox.Id
                    };
                    await installationSite.Create(_dbContext);
                }
            }
            return(new OperationResult(true));
        }