GetJson() public méthode

public GetJson ( ) : string
Résultat string
		public void SaveSiteSettings(SiteSettings siteSettings)
		{
			SiteConfigurationEntity entity = UnitOfWork.FindById<SiteConfigurationEntity>(SiteSettings.SiteSettingsId);

			if (entity == null || entity.Id == Guid.Empty)
			{
				entity = new SiteConfigurationEntity();
				entity.Id = SiteSettings.SiteSettingsId;
				entity.Version = ApplicationSettings.ProductVersion.ToString();
				entity.Content = siteSettings.GetJson();
				UnitOfWork.Add(entity);
			}
			else
			{
				entity.Version = ApplicationSettings.ProductVersion.ToString();
				entity.Content = siteSettings.GetJson();
			}

			UnitOfWork.SaveChanges();
		}
		public void SaveSettings(SiteSettings siteSettings)
		{
			try
			{
				using (IUnitOfWork unitOfWork = _context.CreateUnitOfWork())
				{
					var entity = new Roadkill.Core.Database.LightSpeed.SiteConfigurationEntity();
					entity.Id = SiteSettings.SiteSettingsId;
					entity.Version = ApplicationSettings.ProductVersion;
					entity.Content = siteSettings.GetJson();

					unitOfWork.Add(entity);
					unitOfWork.SaveChanges();
				}
			}
			catch (Exception e)
			{
				throw new DatabaseException(e, "Install failed: unable to connect to the database using '{0}' - {1}", ConnectionString, e.Message);
			}
		}
		public void getjson_should_return_known_json()
		{
			// Arrange
			string expectedJson = @"{
  ""AllowedFileTypes"": ""pdf, swf, avi"",
  ""AllowUserSignup"": true,
  ""IsRecaptchaEnabled"": true,
  ""MarkupType"": ""Markdown"",
  ""RecaptchaPrivateKey"": ""captchaprivatekey"",
  ""RecaptchaPublicKey"": ""captchapublickey"",
  ""SiteUrl"": ""http://siteurl"",
  ""SiteName"": ""my sitename"",
  ""Theme"": ""Mytheme"",
  ""OverwriteExistingFiles"": false,
  ""HeadContent"": """",
  ""MenuMarkup"": ""* %mainpage%\r\n* %categories%\r\n* %allpages%\r\n* %newpage%\r\n* %managefiles%\r\n* %sitesettings%\r\n\r\n"",
  ""PluginLastSaveDate"": ""{today}""
}";

			expectedJson = expectedJson.Replace("{today}", DateTime.Today.ToUniversalTime().ToString("s") + "Z"); // Z = zero offset from UTC

			SiteSettings settings = new SiteSettings();
			settings.AllowedFileTypes = "pdf, swf, avi";
			settings.AllowUserSignup = true;
			settings.IsRecaptchaEnabled = true;
			settings.MarkupType = "Markdown";
			settings.RecaptchaPrivateKey = "captchaprivatekey";
			settings.RecaptchaPublicKey = "captchapublickey";
			settings.SiteUrl = "http://siteurl";
			settings.SiteName = "my sitename";
			settings.Theme = "Mytheme";
			settings.PluginLastSaveDate = DateTime.Today.ToUniversalTime(); // ideally property this would take an IDate...something to refactor in for the future if there are problems.

			// Act
			string actualJson = settings.GetJson();

			// Assert
			Assert.That(actualJson, Is.EqualTo(expectedJson), actualJson);
		}