using System.Collections.Generic; using Luticate2.Utils.Dbo.Result; using Luticate2.Utils.Utils; using WebApiWebSem.DataAccess; using WebApiWebSem.Dbo.Articles; using WebApiWebSem.Dbo.ArticlesFields; using Xunit; namespace Test.DataAccess { public class ArticlesDataAccessTest { [Fact] public void Test1() { Tests.TestRealDb(access => { var res = access.AddDbo(new ArticlesAddDbo { Fields = new List { new ArticlesFieldsAddDbo { Property = "deathDate", Type = "date/date", Value = "1965-01-24" } }, Id = "Winston_Churchill", PictureCaption = "Winston Churchill en 1942.", PictureUrl = "http://commons.wikimedia.org/wiki/Special:FilePath/Sir_Winston_S_Churchill.jpg?width=300", Text = "Winston Churchill, né le 30 novembre 1874 au palais de Blenheim", Type = "person" }); Assert.Equal(LuStatus.Success, res.Status); Assert.Equal("Winston_Churchill", res.Data.Id); }); } [Fact] public void Test2() { Tests.TestRealDb(access => { var res = access.AddDbo(new ArticlesAddDbo { Fields = new List { new ArticlesFieldsAddDbo { Property = "deathDate", Type = "date/date", Value = "1965-01-24" } }, Id = "Winston_Churchill", PictureCaption = "Winston Churchill en 1942.", PictureUrl = "http://commons.wikimedia.org/wiki/Special:FilePath/Sir_Winston_S_Churchill.jpg?width=300", Text = "Winston Churchill, né le 30 novembre 1874 au palais de Blenheim", Type = "person" }); Assert.Equal(LuStatus.Success, res.Status); Assert.Equal("Winston_Churchill", res.Data.Id); var resGet = access.GetSingleById("Winston_Churchill"); Assert.Equal(LuStatus.Success, resGet.Status); Assert.Equal("Winston_Churchill", resGet.Data.Id); Assert.Equal(1, resGet.Data.Fields.Count); Assert.Equal("deathDate", resGet.Data.Fields[0].Property); }); } [Fact] public void Test3() { Tests.TestRealDb(access => { var res = access.AddDbo(new ArticlesAddDbo { Fields = new List { new ArticlesFieldsAddDbo { Property = "deathDate", Type = "date/date", Value = "1965-01-24" } }, Id = "Winston_Churchill", PictureCaption = "Winston Churchill en 1942.", PictureUrl = "http://commons.wikimedia.org/wiki/Special:FilePath/Sir_Winston_S_Churchill.jpg?width=300", Text = "Winston Churchill, né le 30 novembre 1874 au palais de Blenheim", Type = "person" }); Assert.Equal(LuStatus.Success, res.Status); Assert.Equal("Winston_Churchill", res.Data.Id); var resEdit = access.EditSingleByIdDbo("Winston_Churchill", new ArticlesEditDbo { Fields = new List { new ArticlesFieldsAddDbo { Property = "deathDate", Type = "date/date", Value = "1965-01-25" } }, PictureCaption = "Test.", PictureUrl = "http://commons.wikimedia.org/wiki/Special:FilePath/Sir_Winston_S_Churchill.jpg?width=300", Text = "Winston Churchill, né le 30 novembre 1874 au palais de Blenheim" }); Assert.Equal(null, resEdit.Exception); Assert.Equal(LuStatus.Success, resEdit.Status); Assert.Equal("Winston_Churchill", resEdit.Data.Id); Assert.Equal("Test.", resEdit.Data.PictureCaption); Assert.Equal(1, resEdit.Data.Fields.Count); Assert.Equal("deathDate", resEdit.Data.Fields[0].Property); Assert.Equal("1965-01-25", resEdit.Data.Fields[0].Value); var resGet = access.GetSingleById("Winston_Churchill"); Assert.Equal(LuStatus.Success, resGet.Status); Assert.Equal("Winston_Churchill", resGet.Data.Id); Assert.Equal(1, resGet.Data.Fields.Count); Assert.Equal("deathDate", resGet.Data.Fields[0].Property); Assert.Equal("1965-01-25", resGet.Data.Fields[0].Value); }); } } }