예제 #1
0
        public async Task TestAddingSemester()
        {
            ViewModelYearsAndSemesters viewModel = await ViewModelYearsAndSemesters.LoadAsync(LocalAccountId);

            var years = viewModel.School.Years;

            var freshman  = viewModel.School.Years[0];
            var sophomore = viewModel.School.Years[1];
            var junior    = viewModel.School.Years[2];
            var senior    = viewModel.School.Years[3];

            DataChanges changes = new DataChanges();

            changes.Add(new DataItemSemester()
            {
                Identifier      = Guid.NewGuid(),
                UpperIdentifier = freshman.Identifier,
                Name            = "Fall (Freshman)"
            });

            await DataStore.ProcessLocalChanges(changes);

            Assert.AreEqual(1, freshman.Semesters.Count);
            Assert.AreEqual(freshman.Identifier, freshman.Semesters.First().Year.Identifier);
            Assert.AreEqual("Fall (Freshman)", freshman.Semesters.First().Name);
        }
예제 #2
0
        public async Task TestAdding_DateCreated()
        {
            DataChanges changes = new DataChanges();

            // Add multiple at once
            changes.Add(new DataItemYear()
            {
                Identifier = Guid.NewGuid(),
                Name       = "Freshman"
            });

            changes.Add(new DataItemYear()
            {
                Identifier = Guid.NewGuid(),
                Name       = "Sophomore"
            });

            await DataStore.ProcessLocalChanges(changes);


            ViewModelYearsAndSemesters viewModel = await ViewModelYearsAndSemesters.LoadAsync(LocalAccountId);

            var freshman  = viewModel.School.Years[0];
            var sophomore = viewModel.School.Years[1];

            Assert.AreEqual("Freshman", freshman.Name);
            Assert.AreEqual("Sophomore", sophomore.Name);

            // Make sure the second item is 1 tick after the first
            Assert.AreEqual(freshman.DateCreated.AddTicks(1), sophomore.DateCreated);
        }
예제 #3
0
        public async Task TestAddingYear()
        {
            ViewModelYearsAndSemesters viewModel = await ViewModelYearsAndSemesters.LoadAsync(LocalAccountId);

            var years = viewModel.School.Years;

            Assert.AreEqual(0, years.Count);

            DataItemYear year = new DataItemYear()
            {
                Identifier = Guid.NewGuid(),
                Name       = "Freshman"
            };

            DataChanges changes = new DataChanges();

            changes.Add(year);

            await DataStore.ProcessLocalChanges(changes);

            Assert.AreEqual(1, DataStore.TableYears.Count(), "Database count of years incorrect");

            Assert.AreEqual(1, years.Count, "View model didn't update");

            ViewItemYear viewYear = years.First();

            Assert.AreEqual("Freshman", viewYear.Name);
            Assert.AreEqual(year.Identifier, viewYear.Identifier);
            Assert.IsTrue((DateTime.UtcNow - viewYear.DateCreated).TotalSeconds < 2);


            changes = new DataChanges();
            changes.Add(new DataItemYear()
            {
                Identifier = Guid.NewGuid(),
                Name       = "Sophomore"
            });

            await DataStore.ProcessLocalChanges(changes);

            Assert.AreEqual(2, DataStore.TableYears.Count(), "Database count of years incorrect");

            Assert.AreEqual(2, years.Count);

            Assert.AreEqual("Sophomore", years.Last().Name);


            // Sleep so that updated time should be different than created time
            await Task.Delay(20);


            DateTime originalDateCreated = years.First().DateCreated;


            changes = new DataChanges();
            changes.Add(new DataItemYear()
            {
                Identifier = years.First().Identifier,
                Name       = "Freshman Edited"
            });

            await DataStore.ProcessLocalChanges(changes);

            Assert.AreEqual(2, DataStore.TableYears.Count());
            Assert.AreEqual(2, years.Count);

            viewYear = years.First();

            Assert.AreEqual("Freshman Edited", viewYear.Name);
            Assert.AreEqual(originalDateCreated, viewYear.DateCreated);
            Assert.AreNotEqual(viewYear.DateCreated, viewYear.Updated);
        }
        protected override async Task InitializeAfterYears()
        {
            var years = (await ViewModelYearsAndSemesters.LoadAsync(LocalAccountId)).School.Years;

            DataChanges changes = new DataChanges();

            changes.Add(new DataItemSemester()
            {
                Identifier      = Guid.NewGuid(),
                UpperIdentifier = years[0].Identifier,
                Name            = "Fall (Freshman)"
            });

            changes.Add(new DataItemSemester()
            {
                Identifier      = Guid.NewGuid(),
                UpperIdentifier = years[0].Identifier,
                Name            = "Spring (Freshman)"
            });

            changes.Add(new DataItemSemester()
            {
                Identifier      = Guid.NewGuid(),
                UpperIdentifier = years[1].Identifier,
                Name            = "Fall (Sophomore)"
            });

            changes.Add(new DataItemSemester()
            {
                Identifier      = Guid.NewGuid(),
                UpperIdentifier = years[1].Identifier,
                Name            = "Spring (Sophomore)"
            });

            changes.Add(new DataItemSemester()
            {
                Identifier      = Guid.NewGuid(),
                UpperIdentifier = years[2].Identifier,
                Name            = "Fall (Junior)"
            });

            changes.Add(new DataItemSemester()
            {
                Identifier      = Guid.NewGuid(),
                UpperIdentifier = years[2].Identifier,
                Name            = "Spring (Junior)"
            });

            CurrentSemesterId = Guid.NewGuid();

            changes.Add(new DataItemSemester()
            {
                Identifier      = CurrentSemesterId,
                UpperIdentifier = years[3].Identifier,
                Name            = "Fall (Senior)"
            });

            await DataStore.ProcessLocalChanges(changes);

            await InitializeAfterSemesters();
        }