public void ItFetchesACertificateGroupConfigurationFromTheServiceLayer() { // Test syntax: "AAA" see https://msdn.microsoft.com/en-us/library/hh694602.aspx // *Arrange*: setup the current context, in preparation for the test // *Act*: execute an action in the system under test (SUT) // *Assert*: verify that the test succeeded var id = "Default"; var configuration = new CertificateGroupConfigurationModel() { Id = id }; // Inject a fake response when Devices.GetAsync() is invoked // Moq Quickstart: https://github.com/Moq/moq4/wiki/Quickstart _group.Setup(x => x.GetCertificateGroupConfiguration(id)).ReturnsAsync(configuration); // Act // Note: don't use "var" so to implicitly assert that the // method is returning an object of the expected type. We test only // public methods, i.e. to test code inside private methods, we // write a test that starts from a public method. CertificateGroupConfigurationApiModel result = _target.GetCertificateGroupConfigurationAsync(id).Result; // Verify that Devices.GetAsync() has been called, exactly once // with the correct parameters _group.Verify(x => x.GetCertificateGroupConfiguration(It.Is <string>(s => s == id)), Times.Once); }
public async Task <CertificateGroupConfigurationApiModel> UpdateCertificateGroupConfigurationAsync( string group, [FromBody] CertificateGroupConfigurationApiModel config) { var onBehalfOfCertificateGroups = await _certificateGroups.OnBehalfOfRequest(Request); return(new CertificateGroupConfigurationApiModel( group, await onBehalfOfCertificateGroups.UpdateCertificateGroupConfiguration(group, config.ToServiceModel()))); }
public async Task <ActionResult> EditAsync( CertificateGroupConfigurationApiModel newGroup) { if (ModelState.IsValid) { AuthorizeClient(); CertificateGroupConfigurationApiModel group; try { group = await _opcVault.GetCertificateGroupConfigurationAsync(newGroup.Name); } catch (Exception ex) { var error = "Failed to load the certificate group configuration " + newGroup.Name + ". " + "Message:" + ex.Message; return(RedirectToAction("Index", new { error })); } if (group == null) { return(new NotFoundResult()); } // at this point only allow lifetime and Subject update group.SubjectName = newGroup.SubjectName; group.DefaultCertificateLifetime = newGroup.DefaultCertificateLifetime; //group.DefaultCertificateKeySize = newGroup.DefaultCertificateKeySize; //group.DefaultCertificateHashSize = newGroup.DefaultCertificateHashSize; group.IssuerCACertificateLifetime = newGroup.IssuerCACertificateLifetime; //group.IssuerCACertificateKeySize = newGroup.IssuerCACertificateKeySize; //group.IssuerCACertificateHashSize = newGroup.IssuerCACertificateHashSize; //group.IssuerCACRLDistributionPoint = newGroup.IssuerCACRLDistributionPoint; //group.IssuerCAAuthorityInformationAccess = newGroup.IssuerCAAuthorityInformationAccess; try { await _opcVault.UpdateCertificateGroupConfigurationAsync(group.Name, group).ConfigureAwait(false); } catch (Exception ex) { var error = "Failed to update the certificate group configuration " + group.Name + ". " + "Message:" + ex.Message; return(RedirectToAction("Index", new { error })); } return(RedirectToAction("Index")); } return(View(newGroup)); }