예제 #1
0
        public void CanAdd()
        {
            var databaseContext = new DatabaseContext();

            databaseContext.Database.EnsureDeleted();
            databaseContext.Database.EnsureCreated();
            Instant now = SystemClock.Instance.GetCurrentInstant();

            System.Collections.Generic.IEnumerable <DateTimeZone> timeZoneList = DateTimeZoneProviders.Bcl.GetAllZones().ToList();
            DateTimeZone russianTimeZone = timeZoneList.Single(x => x.Id == "Russian Standard Time");
            var          customer        = new Customer()
            {
                Name          = "Joe",
                Created       = now,
                BirthDay      = new LocalDate(2020, 10, 20),
                ZonedDateTime = new ZonedDateTime(SystemClock.Instance.GetCurrentInstant(), russianTimeZone),
            };

            databaseContext.Add(customer);
            databaseContext.SaveChanges();

            databaseContext = new DatabaseContext();
            Customer customerFromDatabase = databaseContext.Customers.Single(x => x.BirthDay == new LocalDate(2020, 10, 20));

            Assert.Equal(customer.Created, customerFromDatabase.Created);
            Assert.Equal(customer.Name, customerFromDatabase.Name);

            // The following is not good. The problem is that SQL server do not have a datatype that contains the timezone.
            Assert.NotEqual(russianTimeZone, customerFromDatabase.ZonedDateTime.Zone);

            databaseContext.Dispose();
        }
예제 #2
0
 public override object GetIndex(Func <object> proceed, object self, System.Collections.Generic.IEnumerable <object> keys)
 {
     if (keys.Count() == 1)
     {
         return(GetMember(proceed, null, System.Convert.ToString(keys.Single())));
     }
     return(proceed());
 }
            public override object GetIndex(Func <object> proceed, object self, System.Collections.Generic.IEnumerable <object> keys)
            {
                if (keys.Count() == 1)
                {
                    var key = System.Convert.ToString(keys.Single());

                    // the zone name is in reference of Layout, e.g. /AsideSecond
                    if (_layoutShape != null && key.StartsWith("/"))
                    {
                        key     = key.Substring(1);
                        _parent = _layoutShape;
                    }

                    return(GetMember(proceed, null, key));
                }
                return(proceed());
            }
        public async Task FociSingInSignOutAsync()
        {
            LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync().ConfigureAwait(false);

            LabUser user          = labResponse.User;
            string  cacheFilePath = null;

            try
            {
                cacheFilePath = Path.GetTempFileName();

                CreateFamilyApps(labResponse, cacheFilePath, out IPublicClientApplication pca_fam1, out IPublicClientApplication pca_fam2, out IPublicClientApplication pca_nonFam);

                var userCacheAccess1 = pca_fam1.UserTokenCache.RecordAccess();
                var userCacheAccess2 = pca_fam2.UserTokenCache.RecordAccess();
                var userCacheAccess3 = pca_nonFam.UserTokenCache.RecordAccess();

                Trace.WriteLine("Get a token interactively with an app from the family.");
                AuthenticationResult authResult = await pca_fam1.AcquireTokenWithDeviceCode(s_scopes, deviceCodeResult =>
                {
                    SeleniumExtensions.PerformDeviceCodeLogin(
                        deviceCodeResult,
                        labResponse.User,
                        TestContext,
                        false);

                    return(Task.FromResult(0));
                }).ExecuteAsync()
                                                  .ConfigureAwait(false);

                MsalAssert.AssertAuthResult(authResult, user);
                userCacheAccess1.AssertAccessCounts(0, 1);
                userCacheAccess2.AssertAccessCounts(0, 0);
                userCacheAccess3.AssertAccessCounts(0, 0);

                Trace.WriteLine("Get a token silently with another app from the family.");
                authResult = await pca_fam2.AcquireTokenSilent(s_scopes, user.Upn)
                             .ExecuteAsync()
                             .ConfigureAwait(false);

                MsalAssert.AssertAuthResult(authResult, user);
                userCacheAccess1.AssertAccessCounts(0, 1);
                userCacheAccess2.AssertAccessCounts(1, 1); // a write occurs because appA does not have an AT, so it needs to refresh the FRT
                userCacheAccess3.AssertAccessCounts(0, 0);

                Trace.WriteLine("Apps that are not part of the family cannot get tokens this way.");
                await AssertException.TaskThrowsAsync <MsalUiRequiredException>(() => pca_nonFam
                                                                                .AcquireTokenSilent(s_scopes, user.Upn)
                                                                                .ExecuteAsync())
                .ConfigureAwait(false);

                userCacheAccess1.AssertAccessCounts(0, 1);
                userCacheAccess2.AssertAccessCounts(1, 1);
                userCacheAccess3.AssertAccessCounts(1, 0);

                Trace.WriteLine("Sing-out from one app - sign out of all apps in the family");
                System.Collections.Generic.IEnumerable <IAccount> accounts = await pca_fam1.GetAccountsAsync().ConfigureAwait(false);

                await pca_fam1.RemoveAsync(accounts.Single()).ConfigureAwait(false);

                System.Collections.Generic.IEnumerable <IAccount> acc2 = await pca_fam2.GetAccountsAsync().ConfigureAwait(false);

                Assert.IsFalse(acc2.Any());
            }
            finally
            {
                if (cacheFilePath != null && File.Exists(cacheFilePath))
                {
                    File.Delete(cacheFilePath);
                }
            }
        }