Exemplo n.º 1
0
        public void Convert()
        {
            var token = new Token()
            {
                ApplicationId = Guid.NewGuid(), 
            };

            var content = new TextContent()
            {
                Active = false,
                Deleted = true,
                Token = token,
            };

            var converted = content.Convert();
            Assert.AreEqual<DateTime>(DateTime.UtcNow.Date, converted.CreatedOn.Date);
            Assert.AreEqual<DateTime>(DateTime.UtcNow.Date, converted.UpdatedOn.Date);
            Assert.AreEqual<Guid>(token.ApplicationId, converted.ApplicationId);
            Assert.IsFalse(content.Active);
            Assert.IsTrue(content.Deleted);
        }
Exemplo n.º 2
0
        public TextContent Store(TextContent text)
        {
            Contract.Requires <ArgumentNullException>(null != text);
            Contract.Requires <ArgumentNullException>(null != text.Token);
            Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != text.Token.ApplicationId);
            Contract.Ensures(Contract.Result <TextContent>() != null);

            using (new PerformanceMonitor())
            {
                var id = Guid.Empty;

                if (Guid.Empty == text.Id)
                {
                    var contentId = this.source.InsertText(text.Content);
                    var data      = text.Convert();
                    data.ContentId = contentId;

                    id = this.source.Insert(data);
                }
                else
                {
                    var data = this.source.SelectText(text.Token.ApplicationId, text.Id);

                    data.Active    = text.Active;
                    data.Deleted   = text.Deleted;
                    data.UpdatedOn = DateTime.UtcNow;

                    this.source.UpdateText(data.ContentId, text.Content);
                    id = this.source.Update(data);
                }

                return(new TextContent()
                {
                    Id = id
                });
            }
        }