Exemplo n.º 1
0
        public async Task ReadAndWriteHosts()
        {
            var fileName = "Test-" + Guid.NewGuid().ToString() + ".json";

            removeList.Add(fileName);
            var repo = new WatchRepo(fileName);
            var list = await repo.GetList();

            var item = new WatchEntity
            {
                Host                = Guid.NewGuid().ToString(),
                Emails              = Guid.NewGuid().ToString(),
                IsEnabled           = true,
                Note                = "text яшерттøæå=,/{}().-|_!#¤$\"'",
                PingIntervalSeconds = 1000
            };

            var b = await repo.Insert(item);

            Assert.IsTrue(b);
            list = await repo.GetList();

            Assert.IsNotNull(list);
            Assert.AreEqual(1, list.Count);

            Assert.AreEqual(item.Host, list[0].Host);
            Assert.AreEqual(item.Note, list[0].Note);;
        }
Exemplo n.º 2
0
        public async Task <bool> Insert(WatchEntity entity)
        {
            var list = await GetList();

            if (list != null)
            {
                if (list.Any(e => { if (e.Host == entity.Host)
                                    {
                                        return(true);
                                    }
                                    return(false); }))
                {
                    return(false);
                }
            }
            else
            {
                list = new List <WatchEntity>();
            }

            entity.WatchId = Guid.NewGuid();
            list.Add(entity);
            await SaveList(list);

            return(true);
        }
Exemplo n.º 3
0
        public async Task UpdateHostTest()
        {
            var e = new WatchEntity
            {
                Emails = Guid.NewGuid().ToString(),
                Host   = Guid.NewGuid().ToString(),
                PingIntervalSeconds = 5
            };
            await RepoContext.Insert(e);

            var e2 = new WatchEntity
            {
                WatchId             = e.WatchId,
                Emails              = Guid.NewGuid().ToString(),
                Host                = Guid.NewGuid().ToString(),
                PingIntervalSeconds = 2
            };

            await RepoContext.Update(e2);

            var e3 = await RepoContext.GetItem(e.WatchId);

            Assert.AreEqual(e.WatchId, e3.WatchId);
            Assert.AreEqual(e2.Emails, e3.Emails, "email does not match");
            Assert.AreEqual(e2.Host, e3.Host);
            Assert.AreEqual(e2.PingIntervalSeconds, e3.PingIntervalSeconds);
        }
Exemplo n.º 4
0
        public async Task <bool> Insert(WatchEntity entity)
        {
            entity.WatchId = Guid.NewGuid();
            await WatchEntities.AddAsync(entity);

            await SaveChangesAsync();

            return(true);
        }
Exemplo n.º 5
0
        public async Task <bool> Update(WatchEntity entity)
        {
            var list = await GetList();

            var e = list.FirstOrDefault(q => { return(q.WatchId == entity.WatchId); });

            list[list.IndexOf(e)] = entity;
            await SaveList(list);

            return(true);
        }
Exemplo n.º 6
0
        public async Task <bool> Update(WatchEntity entity)
        {
            var c = await this.Database.ExecuteSqlInterpolatedAsync($@"update WatchEntities set 
Emails ={entity.Emails},
Host ={entity.Host},
IsOnline ={entity.IsOnline},
IsEnabled ={entity.IsEnabled},
PingIntervalSeconds ={entity.PingIntervalSeconds},
Note = {entity.Note}
where WatchId = {entity.WatchId}");

            return(c == 1);
        }
Exemplo n.º 7
0
        public async Task WriteReadHostTests()
        {
            var e = new WatchEntity {
                WatchId             = Guid.NewGuid(),
                Emails              = Guid.NewGuid().ToString(),
                Host                = Guid.NewGuid().ToString(),
                PingIntervalSeconds = 1000
            };
            var result = await RepoContext.AddAsync(e);

            await RepoContext.SaveChangesAsync();

            Assert.AreEqual(e.WatchId, result.Entity.WatchId);
        }
Exemplo n.º 8
0
        public UpdateHostWindowViewModel(WatchEntity entity = null)
        {
            Host = new WatchEntity();

            if (entity != null)
            {
                Host.WatchId             = entity.WatchId;
                Host.Host                = entity.Host;
                Host.Emails              = entity.Emails;
                Host.PingIntervalSeconds = entity.PingIntervalSeconds;
                Host.IsEnabled           = entity.IsEnabled;
                Host.Note                = entity.Note;
            }
        }
Exemplo n.º 9
0
        public async Task AddRemoveTests()
        {
            var fileName = "Test-" + Guid.NewGuid().ToString() + ".json";

            removeList.Add(fileName);
            var repo = new WatchRepo(fileName);

            var item = new WatchEntity
            {
                Host                = Guid.NewGuid().ToString(),
                Emails              = Guid.NewGuid().ToString(),
                IsEnabled           = true,
                Note                = Guid.NewGuid().ToString(),
                PingIntervalSeconds = 1000
            };

            var item2 = new WatchEntity
            {
                Host                = Guid.NewGuid().ToString(),
                Emails              = Guid.NewGuid().ToString(),
                IsEnabled           = true,
                Note                = Guid.NewGuid().ToString(),
                PingIntervalSeconds = 1000
            };

            await repo.Insert(item);

            await repo.Insert(item2);

            var list = await repo.GetList();

            Assert.AreEqual(2, list.Count);

            await repo.Remove(item.WatchId);

            list = await repo.GetList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(item2.Host, list[0].Host);

            File.Delete(fileName);
        }
Exemplo n.º 10
0
        public async Task DeleteHostTests()
        {
            var e = new WatchEntity
            {
                WatchId             = Guid.NewGuid(),
                Emails              = Guid.NewGuid().ToString(),
                Host                = Guid.NewGuid().ToString(),
                PingIntervalSeconds = 1000
            };

            var result = await RepoContext.AddAsync(e);

            await RepoContext.SaveChangesAsync();

            Assert.AreEqual(e.WatchId, result.Entity.WatchId);

            await RepoContext.Remove(e.WatchId);

            var e2 = await RepoContext.GetItem(e.WatchId);

            Assert.IsNull(e2);
        }
Exemplo n.º 11
0
        public async Task UpdateTests()
        {
            var fileName = "Test-" + Guid.NewGuid().ToString() + ".json";

            removeList.Add(fileName);
            var repo = new WatchRepo(fileName);

            var item = new WatchEntity
            {
                Host                = Guid.NewGuid().ToString(),
                Emails              = Guid.NewGuid().ToString(),
                IsEnabled           = true,
                Note                = Guid.NewGuid().ToString(),
                PingIntervalSeconds = 1000
            };

            await repo.Insert(item);

            item.Host                = Guid.NewGuid().ToString();
            item.Emails              = Guid.NewGuid().ToString();
            item.IsEnabled           = false;
            item.Note                = Guid.NewGuid().ToString();
            item.PingIntervalSeconds = 2000;

            await repo.Update(item);

            var list = await repo.GetList();

            Assert.AreEqual(1, list.Count);

            Assert.AreEqual(item.WatchId, list[0].WatchId);
            Assert.AreEqual(item.Host, list[0].Host);
            Assert.AreEqual(item.Emails, list[0].Emails);
            Assert.AreEqual(item.IsEnabled, list[0].IsEnabled);
            Assert.AreEqual(item.Note, list[0].Note);
            Assert.AreEqual(item.PingIntervalSeconds, list[0].PingIntervalSeconds);

            File.Delete(fileName);
        }
Exemplo n.º 12
0
 public async Task UpdateAsync(WatchEntity entity)
 {
     await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false);
 }
Exemplo n.º 13
0
 public async Task RemoveAsync(WatchEntity entity)
 {
     await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false);
 }
Exemplo n.º 14
0
 public async Task <WatchEntity> AddAsync(WatchEntity entity)
 {
     return(await Client.PostAsync <WatchEntity, WatchEntity>(entity, "Create", entity).ConfigureAwait(false));
 }
Exemplo n.º 15
0
 public AddHostWindowViewModel()
 {
     Host      = new WatchEntity();
     Host.Host = "localhost";
     Host.PingIntervalSeconds = 50;
 }
Exemplo n.º 16
0
 public UpdateHostWindow(WatchEntity entity)
 {
     InitializeComponent();
     viewModel = new UpdateHostWindowViewModel(entity);
 }