public void IndexReturnsTheTenantInTheModel() { using (var controller = new AccountController(null, null)) { Tenant tenant = new Tenant(); controller.Tenant = tenant; var result = controller.Index() as ViewResult; var model = result.ViewData.Model as TenantPageViewData<Tenant>; Assert.AreSame(tenant, model.ContentModel); } }
public ActionResult New(Tenant tenant) { if (string.IsNullOrWhiteSpace(tenant.Name) || tenant.Name.Equals("new", System.StringComparison.InvariantCultureIgnoreCase)) { this.ModelState.AddModelError("ContentModel.Name", "* Organization name cannot be empty or 'new'."); } else if (this.tenantStore.GetTenant(tenant.Name) != null) { this.ModelState.AddModelError("ContentModel.Name", "* Organization name already used."); } if (!this.ModelState.IsValid) { var model = new TenantPageViewData<Tenant>(tenant) { Title = "New Tenant : Error!" }; return this.View(model); } this.tenantStore.SaveTenant(tenant); return this.RedirectToAction("Index"); }
public void ExportGetsTheTenantInformationAndPutsInModel() { var tenant = new Tenant(); var mockTenantStore = new Mock<ITenantStore>(); var mockSurveyAnswerStore = new Mock<ISurveyAnswerStore>(); mockTenantStore.Setup(r => r.GetTenant(It.IsAny<string>())).Returns(tenant); mockSurveyAnswerStore.Setup(r => r.GetFirstSurveyAnswerId(It.IsAny<string>(), It.IsAny<string>())).Returns(string.Empty); using (var controller = new SurveysController(null, mockSurveyAnswerStore.Object, null, mockTenantStore.Object, null, null)) { controller.Tenant = tenant; var result = controller.ExportResponses(string.Empty) as ViewResult; var model = result.ViewData.Model as TenantPageViewData<ExportResponseModel>; Assert.AreSame(tenant, model.ContentModel.Tenant); } }
public void ExportDeterminesIfThereAreResponsesToExport() { var mockTenantStore = new Mock<ITenantStore>(); var mockSurveyAnswerStore = new Mock<ISurveyAnswerStore>(); var tenant = new Tenant(); mockTenantStore.Setup(r => r.GetTenant(It.IsAny<string>())).Returns(tenant); mockSurveyAnswerStore.Setup(r => r.GetFirstSurveyAnswerId(It.IsAny<string>(), It.IsAny<string>())).Returns(string.Empty); using (var controller = new SurveysController(null, mockSurveyAnswerStore.Object, null, mockTenantStore.Object, null, null)) { var result = controller.ExportResponses(string.Empty) as ViewResult; var model = result.ViewData.Model as TenantPageViewData<ExportResponseModel>; Assert.AreEqual(false, model.ContentModel.HasResponses); } }
public void RemoveFieldForRemovesCustomField() { // Setup const string Tenant = "tenant"; var mockTenant = new Tenant { Name = Tenant, SubscriptionKind = Shared.Models.SubscriptionKind.Premium }; var metadata = new UDFMetadata { Name = "custom", Display = "display" }; var mockTenantStore = new Mock<ITenantStore>(); mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant); var udfDictionary = new UDFDictionary(mockTenantStore.Object); IEnumerable<UDFMetadataError> errors = new List<UDFMetadataError>(); var result = udfDictionary.AddFieldFor<TestExtension>(Tenant, metadata, out errors); var f1 = udfDictionary.GetFieldsFor<TestExtension>(Tenant); // Act udfDictionary.RemoveFieldFor<TestExtension>(Tenant, "custom"); var fields = udfDictionary.GetFieldsFor<TestExtension>(Tenant); // Assert mockTenantStore.Verify(m => m.SaveTenant(mockTenant)); Assert.AreEqual(0, fields.Count()); }
public void GetFieldsForReturnsNullWhenEmptyList() { // Setup const string Tenant = "tenant"; var mockTenant = new Tenant { Name = Tenant, SubscriptionKind = Shared.Models.SubscriptionKind.Premium }; var metadata = new UDFMetadata { Name = "custom", Display = "display" }; var mockTenantStore = new Mock<ITenantStore>(); mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant); var udfDictionary = new UDFDictionary(mockTenantStore.Object); // Act var fields = udfDictionary.GetFieldsFor<TestExtension>(Tenant); // Assert Assert.IsNull(fields); }
public void AreValidForReturnsTrueWhenExtensionListMatchesModelList() { // Setup const string Tenant = "tenant"; var mockTenant = new Tenant { Name = Tenant, SubscriptionKind = Shared.Models.SubscriptionKind.Premium }; var list = new List<UDFItem> { new UDFItem { DefaultValue = "defaultvalue", Name = "name", Value = "value", Display = "display" } }; var testModel = new TestExtension(); var mockTenantStore = new Mock<ITenantStore>(); mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant); var metadata = new UDFMetadata { Name = "custom", Display = "display" }; var udfDictionary = new UDFDictionary(mockTenantStore.Object); IEnumerable<UDFMetadataError> errors = new List<UDFMetadataError>(); udfDictionary.AddFieldFor<TestExtension>(Tenant, metadata, out errors); // Act var result = udfDictionary.AreValidFor<TestExtension>(Tenant, list); // Assert Assert.IsTrue(result); }
public void AreValidForReturnsFalseWhenExtensionListDoesNotMatchModelList() { // Setup const string Tenant = "tenant"; var mockTenant = new Tenant { Name = Tenant, SubscriptionKind = Shared.Models.SubscriptionKind.Premium }; var list = new List<UDFItem> { new UDFItem { DefaultValue = "defaultvalue", Name = "name", Value = "value", Display = "display" } }; var testModel = new TestExtension(); var mockTenantStore = new Mock<ITenantStore>(); mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant); var udfDictionary = new UDFDictionary(mockTenantStore.Object); // Act var result = udfDictionary.AreValidFor<TestExtension>(Tenant, list); // Assert Assert.IsFalse(result); }
public void SaveTenant(Tenant tenant) { this.tenantBlobContainer.Save(tenant.Name.ToLowerInvariant(), tenant); if (this.CacheEnabled) { TenantCacheHelper.AddToCache(tenant.Name, TenantAccountTag, tenant); } }