public void Returns_uncertified_deployments_by_application_and_environment() { var criteria = new CriterionSet(); criteria.AddCriterion(new Criterion(Deployment.APPLICATION, "SampleApp1")); criteria.AddCriterion(new Criterion(Deployment.ENVIRONMENT, "Environment")); criteria.AddCriterion(new Criterion(Deployment.CERTIFIED_ON, null)); criteria.AddCriterion(new Criterion(Deployment.RESULT, DeploymentResult.Success)); criteria.OrderBy = Deployment.DEPLOYED_ON; criteria.SortOrder = SortOrder.Descending; var foundDeployments = new Deployment[0]; var mocks = new MockRepository(); var repository = mocks.CreateMock<IPersistentObjectRepository>(); using (mocks.Record()) { repository.ConfigurationFile = "deployer.hibernate.cfg.xml"; Expect.Call(repository.FindAll<Deployment>(criteria)).Return(foundDeployments); } using (mocks.Playback()) { IDeploymentRepository deploymentRepository = new DeploymentRepository(repository); var deployments = deploymentRepository.FindSuccessfulUncertified("SampleApp1", "Environment"); Assert.That(deployments, Is.SameAs(foundDeployments)); } mocks.VerifyAll(); }
public void Records_deployment() { var deployment = new Deployment{ Version = "1.0"}; var mocks = new MockRepository(); var factory = mocks.CreateMock<IDeploymentFactory>(); var repository = mocks.CreateMock<IDeploymentRepository>(); var context = mocks.CreateMock<ISecurityContext>(); using (mocks.Record()) { Expect.Call(context.GetCurrentUsername()).Return("jsmith"); Expect.Call(factory.CreateDeployment("application", "environment", "jsmith", "Output...", "1.0", false)).Return(deployment); repository.Save(deployment); } using (mocks.Playback()) { IDeploymentRecorder recorder = new DeploymentRecorder(context, factory, repository); var version = recorder.RecordDeployment("application", "environment", "Output...", "1.0", false); Assert.That(version, Is.EqualTo("1.0")); } mocks.VerifyAll(); }
public void Certifies_deployment() { var deployment = new Deployment(); var mocks = new MockRepository(); var clock = mocks.CreateMock<ISystemClock>(); var securityContext = mocks.CreateMock<ISecurityContext>(); var repository = mocks.CreateMock<IDeploymentRepository>(); using (mocks.Record()) { Expect.Call(clock.GetCurrentDateTime()).Return(new DateTime(2007, 4, 15)); Expect.Call(securityContext.GetCurrentUsername()).Return("khurwitz"); repository.Save(deployment); } using (mocks.Playback()) { IVersionCertifier certifier = new VersionCertifier(clock, securityContext, repository); certifier.Certify(deployment); Assert.That(deployment.CertifiedBy, Is.EqualTo("khurwitz")); Assert.That(deployment.CertifiedOn, Is.EqualTo(new DateTime(2007, 4, 15))); } mocks.VerifyAll(); }
public void Constructs_deployment_row() { var deployment = new Deployment { Version = "845", DeployedOn = new DateTime(2007, 4, 15, 6, 45, 32), DeployedBy = "khurwitz", Result = DeploymentResult.Failure, CertifiedOn = new DateTime(2007, 5, 15, 8, 45, 32), CertifiedBy = "jpalermo", Output = new DeploymentOutput {Output = "Output..."} }; IDeploymentRowFactory factory = new DeploymentRowFactory(); string[] row = factory.ConstructRow(deployment); Assert.That(row.Length, Is.EqualTo(7)); Assert.That(row[0], Is.EqualTo("845")); Assert.That(row[1], Is.EqualTo("4/15/2007 6:45 AM")); Assert.That(row[2], Is.EqualTo("khurwitz")); Assert.That(row[3], Is.EqualTo("Failure")); Assert.That(row[4], Is.EqualTo("5/15/2007 8:45 AM")); Assert.That(row[5], Is.EqualTo("jpalermo")); }
public void Generates_certification_label_text() { Deployment deployment = new Deployment(); deployment.CertifiedBy = "khurwitz"; deployment.CertifiedOn = new DateTime(2007, 4, 15, 8, 32, 45); MockRepository mocks = new MockRepository(); IDeploymentSelectionValidator validator = mocks.CreateMock<IDeploymentSelectionValidator>(); using (mocks.Record()) { Expect.Call(validator.IsValid("845", deployment)).Return(true); } using (mocks.Playback()) { ILabelTextGenerator textGenerator = new LabelTextGenerator(validator); string text = textGenerator.GetCertificationText("845", deployment); Assert.That(text, Is.EqualTo("4/15/2007 8:32 AM by khurwitz")); } mocks.VerifyAll(); }
public void Certify(Deployment deployment) { if (deployment != null) { deployment.CertifiedBy = _securityContext.GetCurrentUsername(); deployment.CertifiedOn = _clock.GetCurrentDateTime(); _repository.Save(deployment); } }
public string[] ConstructRow(Deployment deployment) { string version = deployment.Version; string deployedOn = deployment.DeployedOn.ToString("g"); string deployedBy = deployment.DeployedBy; string result = deployment.Result.DisplayName; string certifiedOn = deployment.CertifiedOn != null ? deployment.CertifiedOn.Value.ToString("g") : string.Empty; string certifiedBy = deployment.CertifiedBy; string deploymentId = deployment.Id.ToString(); return new[] {version, deployedOn, deployedBy, result, certifiedOn, certifiedBy, deploymentId}; }
public Deployment CreateDeployment(string application, string environment, string deployedBy, string output, string version, bool failed) { var deployment = new Deployment { Application = application, Environment = environment, Version = version, DeployedBy = deployedBy, DeployedOn = _clock.GetCurrentDateTime(), Result = (failed || (_resultCalculator.GetResult(output) == DeploymentResult.Failure)) ? DeploymentResult.Failure : DeploymentResult.Success }; deployment.SetOutput(new DeploymentOutput {Output = output}); return deployment; }
public void Can_persist_deployment() { var deployment = new Deployment { Application = "SampleApp1", Environment = "Development", CertifiedBy = "Certifer", DeployedBy = "Deployer", DeployedOn = new DateTime(2007, 3, 15), CertifiedOn = new DateTime(2007, 4, 15), Version = "250", Result = DeploymentResult.Failure }; var output = new DeploymentOutput { Output = "Output text", Deployment = deployment }; deployment.SetOutput(output); AssertObjectCanBePersisted(deployment); }
public void Correctly_saves_deployment() { var deployment = new Deployment(); var mocks = new MockRepository(); var repository = mocks.CreateMock<IPersistentObjectRepository>(); using (mocks.Record()) { repository.ConfigurationFile = "deployer.hibernate.cfg.xml"; repository.Save(deployment); } using (mocks.Playback()) { IDeploymentRepository deploymentRepository = new DeploymentRepository(repository); deploymentRepository.Save(deployment); } }
private string getText(Environment environment, string versionNumber, Deployment deployment, Action action) { var text = new StringBuilder(); if (_validator.IsValid(versionNumber, deployment)) { var isDeployment = action == Action.Deploy; var username = isDeployment ? deployment.DeployedBy : deployment.CertifiedBy; var date = isDeployment ? deployment.DeployedOn : deployment.CertifiedOn.GetValueOrDefault(); if (environment != null) { text.AppendFormat("{0} on ", environment.Predecessor); } text.AppendFormat("{0} by {1}", date.ToString("g"), username); } return text.ToString(); }
protected override void SetupDatabase() { _uncertified_Application1_Environment1 = new Deployment(); _uncertified_Application1_Environment2 = new Deployment(); _uncertified_Application2_Environment1 = new Deployment(); _uncertified_Application2_Environment2 = new Deployment(); _certified_Application1_Environment1 = new Deployment(); _certified_Application1_Environment2 = new Deployment(); _certified_Application2_Environment1 = new Deployment(); _certified_Application2_Environment2 = new Deployment(); _uncertified_failure = new Deployment(); _certified_failure = new Deployment(); _uncertified_Application1_Environment1.Version = "1"; _uncertified_Application1_Environment2.Version = "2"; _uncertified_Application2_Environment1.Version = "3"; _uncertified_Application2_Environment2.Version = "4"; _certified_Application1_Environment1.Version = "5"; _certified_Application1_Environment2.Version = "6"; _certified_Application2_Environment1.Version = "7"; _certified_Application2_Environment2.Version = "8"; _uncertified_failure.Version = "9"; _certified_failure.Version = "10"; _uncertified_Application1_Environment1.Result = DeploymentResult.Success; _uncertified_Application1_Environment2.Result = DeploymentResult.Success; _uncertified_Application2_Environment1.Result = DeploymentResult.Success; _uncertified_Application2_Environment2.Result = DeploymentResult.Success; _certified_Application1_Environment1.Result = DeploymentResult.Success; _certified_Application1_Environment2.Result = DeploymentResult.Success; _certified_Application2_Environment1.Result = DeploymentResult.Success; _certified_Application2_Environment2.Result = DeploymentResult.Success; _uncertified_failure.Result = DeploymentResult.Failure; _certified_failure.Result = DeploymentResult.Failure; _uncertified_Application1_Environment1.Application = "A1"; _uncertified_Application1_Environment2.Application = "A1"; _uncertified_Application2_Environment1.Application = "A2"; _uncertified_Application2_Environment2.Application = "A2"; _certified_Application1_Environment1.Application = "A1"; _certified_Application1_Environment2.Application = "A1"; _certified_Application2_Environment1.Application = "A2"; _certified_Application2_Environment2.Application = "A2"; _uncertified_Application1_Environment1.Environment = "E1"; _uncertified_Application1_Environment2.Environment = "E2"; _uncertified_Application2_Environment1.Environment = "E1"; _uncertified_Application2_Environment2.Environment = "E2"; _certified_Application1_Environment1.Environment = "E1"; _certified_Application1_Environment2.Environment = "E2"; _certified_Application2_Environment1.Environment = "E1"; _certified_Application2_Environment2.Environment = "E2"; _uncertified_failure.Application = "A1"; _uncertified_failure.Environment = "E2"; _certified_failure.Application = "A1"; _certified_failure.Environment = "E2"; _certified_Application1_Environment1.CertifiedOn = new DateTime(2007, 4, 15); _certified_Application1_Environment2.CertifiedOn = new DateTime(2007, 4, 15); _certified_Application2_Environment1.CertifiedOn = new DateTime(2007, 4, 15); _certified_Application2_Environment2.CertifiedOn = new DateTime(2007, 4, 15); _uncertified_Application1_Environment1.DeployedOn = new DateTime(2007, 4, 15); _uncertified_Application1_Environment2.DeployedOn = new DateTime(2007, 4, 16); _uncertified_Application2_Environment1.DeployedOn = new DateTime(2007, 4, 17); _uncertified_Application2_Environment2.DeployedOn = new DateTime(2007, 4, 18); _certified_Application1_Environment1.DeployedOn = new DateTime(2007, 4, 19); _certified_Application1_Environment2.DeployedOn = new DateTime(2007, 4, 20); _certified_Application2_Environment1.DeployedOn = new DateTime(2007, 4, 21); _certified_Application2_Environment2.DeployedOn = new DateTime(2007, 4, 22); _uncertified_failure.DeployedOn = new DateTime(2007, 3, 2); _certified_failure.DeployedOn = new DateTime(2007, 3, 1); _certified_failure.CertifiedOn = new DateTime(2007, 6, 5); Save( _certified_Application1_Environment1, _certified_Application1_Environment2, _certified_Application2_Environment1, _certified_Application2_Environment2, _uncertified_Application1_Environment1, _uncertified_Application1_Environment2, _uncertified_Application2_Environment1, _uncertified_Application2_Environment2, _uncertified_failure, _certified_failure); }
public void Saves_new_deployment() { var deploymentRepository = getRepository(); var deployment = new Deployment {Application = "MyApplication", DeployedOn = new DateTime(2008, 8, 15)}; deploymentRepository.Save(deployment); GetSession().Dispose(); using (ISession session = GetSession()) { var reloadedDeployment = session.Load<Deployment>(deployment.Id); Assert.That(reloadedDeployment, Is.EqualTo(deployment)); } }
public string GetDeploymentText(Environment environment, string versionNumberText, Deployment deployment) { return getText(environment, versionNumberText, deployment, Action.Deploy); }
public void Save(Deployment deployment) { _repository.Save(deployment); }
public bool IsValid(string versionNumberText, Deployment selectedDeployment) { bool isValidDeployment = (versionNumberText != string.Empty) && (selectedDeployment != null); return isValidDeployment; }
public string GetCertificationText(string versionNumberText, Deployment deployment) { return getText(null, versionNumberText, deployment, Action.Certify); }