Ejemplo n.º 1
0
        public void RoundTripBinaryData()
        {
            byte[] rawData = new byte[1024];
            Random random  = new Random();

            random.NextBytes(rawData);

            BinaryContent data = new BinaryContent()
            {
                Content     = rawData,
                ContentType = "na",
            };
            ContentCore core     = new ContentCore();
            var         returned = core.Store(data);

            Assert.IsNotNull(returned, "Nothing returned");
            Assert.AreNotEqual <Guid>(Guid.Empty, returned.Id, "Identifier not set.");

            var returnedData = core.Get(returned);

            Assert.IsNotNull(returnedData);
            Assert.AreEqual <int>(data.Content.Length, returnedData.Content.Length, "Data is inconsistant.");

            for (int i = 0; i < data.Content.Length; i++)
            {
                if (data.Content[i] != returnedData.Content[i])
                {
                    Assert.Fail("Data is inconsistant.");
                }
            }
        }
Ejemplo n.º 2
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="contentCore">SMAPI's core content logic.</param>
 /// <param name="contentManager">The content manager for this mod.</param>
 /// <param name="modFolderPath">The absolute path to the mod folder.</param>
 /// <param name="modID">The unique ID of the relevant mod.</param>
 /// <param name="modName">The friendly mod name for use in errors.</param>
 /// <param name="monitor">Encapsulates monitoring and logging.</param>
 public ContentHelper(ContentCore contentCore, ContentManagerShim contentManager, string modFolderPath, string modID, string modName, IMonitor monitor)
     : base(modID)
 {
     this.ContentCore    = contentCore;
     this.ContentManager = contentManager;
     this.ModFolderPath  = modFolderPath;
     this.ModName        = modName;
     this.Monitor        = monitor;
 }
Ejemplo n.º 3
0
        public void GetBlogEntrySectionIdentifierEmpty()
        {
            var core  = new ContentCore();
            var entry = new BlogEntry()
            {
                Content           = StringHelper.ValidString(),
                Identifier        = Guid.NewGuid(),
                PostedOn          = DateTime.UtcNow,
                SectionIdentifier = Guid.Empty,
                Title             = StringHelper.ValidString(),
            };

            core.Get(entry);
        }
Ejemplo n.º 4
0
        public void StoreBlogEntryContentInvalid()
        {
            var core  = new ContentCore();
            var entry = new BlogEntry()
            {
                Content           = StringHelper.NullEmptyWhiteSpace(),
                Identifier        = Guid.NewGuid(),
                PostedOn          = DateTime.UtcNow,
                SectionIdentifier = Guid.NewGuid(),
                Title             = StringHelper.ValidString(),
            };

            core.Store(entry);
        }
Ejemplo n.º 5
0
        public void RoundTripBlogEntry()
        {
            var core  = new ContentCore();
            var entry = new BlogEntry()
            {
                Content           = StringHelper.ValidString(),
                PostedOn          = DateTime.UtcNow,
                SectionIdentifier = Guid.NewGuid(),
                Title             = StringHelper.ValidString(),
            };

            core.Store(entry);

            var item = core.Get(entry).FirstOrDefault();

            Assert.AreNotEqual <Guid>(Guid.Empty, item.Identifier);
            Assert.AreEqual <Guid>(entry.SectionIdentifier, item.SectionIdentifier);
            Assert.AreEqual <DateTime>(entry.PostedOn.Date, item.PostedOn.Date);
            Assert.AreEqual <string>(entry.Title, item.Title);
            Assert.IsNotNull(item.Content);
        }
Ejemplo n.º 6
0
        public void GetBlogEntryNull()
        {
            var core = new ContentCore();

            core.Get((BlogEntry)null);
        }
Ejemplo n.º 7
0
        public void StoreBlogEntryNull()
        {
            var core = new ContentCore();

            core.Store((BlogEntry)null);
        }
Ejemplo n.º 8
0
        public void RoundTripXmlContent()
        {
            const string Xml   = "<xml>{0}</xml>";
            Token        token = new Token()
            {
                ApplicationId = Guid.NewGuid()
            };
            XmlContent data = new XmlContent()
            {
                Active    = true,
                Content   = string.Format(Xml, Guid.NewGuid()),
                CreatedOn = DateTime.UtcNow,
                Deleted   = true,
                UpdatedOn = DateTime.UtcNow,
                Token     = token
            };

            Assert.AreEqual <Guid>(Guid.Empty, data.Id);

            ContentCore core     = new ContentCore();
            XmlContent  returned = core.Store(data);

            Assert.IsNotNull(returned);
            Assert.AreNotEqual <Guid>(Guid.Empty, returned.Id);

            XmlContent query = new XmlContent()
            {
                Token = token,
                Id    = returned.Id
            };

            XmlContent filled = core.Get(query);

            Assert.IsNotNull(filled);
            Assert.AreEqual <Guid>(returned.Id, filled.Id);
            Assert.AreEqual <bool>(data.Active, filled.Active, "Data Mismatch");
            Assert.AreEqual <string>(data.Content, filled.Content, "Data Mismatch");
            Assert.AreEqual <DateTime>(data.CreatedOn.Date, filled.CreatedOn.Date, "Data Mismatch");
            Assert.AreEqual <bool>(data.Deleted, filled.Deleted, "Data Mismatch");
            Assert.AreEqual <DateTime>(data.UpdatedOn.Date, filled.UpdatedOn.Date, "Data Mismatch");

            filled.Active    = false;
            filled.Content   = string.Format(Xml, Guid.NewGuid());
            filled.CreatedOn = DateTime.UtcNow;
            filled.Deleted   = false;
            filled.UpdatedOn = DateTime.UtcNow;
            filled.Token     = token;

            returned = core.Store(filled);
            Assert.IsNotNull(returned);
            Assert.AreEqual <Guid>(filled.Id, returned.Id);

            returned.Token = token;
            XmlContent updated = core.Get(returned);

            Assert.IsNotNull(updated);
            Assert.AreEqual <Guid>(filled.Id, updated.Id);
            Assert.AreEqual <bool>(filled.Active, updated.Active, "Data Mismatch");
            Assert.AreEqual <string>(filled.Content, updated.Content, "Data Mismatch");
            Assert.AreEqual <DateTime>(filled.CreatedOn.Date, updated.CreatedOn.Date, "Data Mismatch");
            Assert.AreEqual <bool>(filled.Deleted, updated.Deleted, "Data Mismatch");
            Assert.AreEqual <DateTime>(filled.UpdatedOn.Date, updated.UpdatedOn.Date, "Data Mismatch");
        }