Пример #1
0
        public void WriteOnceReadTwice()
        {
            int beforeProfileAdd  = 0;
            int afterProfileAdded = 0;
            var account1Name      = new AccountName("account1");

            AccountCollection.GetOrCreate(account1Name);
            ExecuteConcurrently(() =>
            {
                Interlocked.Increment(ref beforeProfileAdd);
                IAccount account = AccountCollection.GetOrCreate(account1Name);
                account.Profiles.Add(new ProfileCreationArgs(new ProfileName("~"), new object()));
                Interlocked.Increment(ref afterProfileAdded);
            }, () =>
            {
                var accountFirstVersion  = AccountCollection.GetOrCreate(account1Name);
                var accountSecondVersion = AccountCollection.GetOrCreate(account1Name);
                bool sameVersion         = false;
                if (Interlocked.Increment(ref beforeProfileAdd) == 1)
                {
                    sameVersion = (accountFirstVersion == accountSecondVersion);
                    sameVersion.Should(Be.True);
                }
                if (Interlocked.Increment(ref afterProfileAdded) == 2)
                {
                    IAccount latestAccountVersion = AccountCollection.GetOrCreate(account1Name);
                    latestAccountVersion.Profiles.Count().Should(Be.EqualTo(1));
                    if (sameVersion)
                    {
                        (latestAccountVersion == accountFirstVersion).Should(Be.False);
                    }
                }
            });
            AccountCollection.GetOrCreate(account1Name).Profiles.Count().Should(Be.EqualTo(1));
        }
 public void ReadRead()
 {
     _account.Profiles.Add(new ProfileCreationArgs("Profile", new SampleJiraProfile {
         JiraLogin = "******"
     }));
     ExecuteConcurrently(ReadProfile, ReadProfile);
     AccountCollection.GetOrCreate(ACCOUNT_NAME).Profiles.Count().Should(Be.EqualTo(1));
 }
Пример #3
0
        private void ReadAccountProfiles(string accountName)
        {
            var account = AccountCollection.GetOrCreate(accountName);

            foreach (var profile in account.Profiles)
            {
                profile.Name.Value.Should(Be.StringContaining("profile"));
            }
        }
Пример #4
0
        public void WriteTwiceReadTwice()
        {
            int afterAccountAdded = 0;
            var account1Name      = new AccountName("account1");
            var account2Name      = new AccountName("account2");

            ExecuteConcurrently(() =>
            {
                AccountCollection.GetOrCreate(account1Name);
                AccountCollection.GetOrCreate(account2Name);
                Interlocked.Increment(ref afterAccountAdded);
            }, () =>
            {
                if (Interlocked.Increment(ref afterAccountAdded) == 2)
                {
                    AccountCollection.Count().Should(Be.EqualTo(2));
                }
            });
            AccountCollection.Count().Should(Be.EqualTo(2));
        }
 protected override void OnInit()
 {
     base.OnInit();
     _account = AccountCollection.GetOrCreate(ACCOUNT_NAME);
 }
Пример #6
0
 public void AddAccount(string accountName)
 {
     AccountCollection.GetOrCreate(new AccountName(accountName));
 }
Пример #7
0
 private void AddAccountProfile(string accountName, string profileName)
 {
     AccountCollection.GetOrCreate(accountName).Profiles.Add(new ProfileCreationArgs(profileName, new object()));
 }
Пример #8
0
 public void ReadRead()
 {
     AddAccountProfile(ACCOUNT_NAME, "profile1");
     ExecuteConcurrently(() => ReadAccountProfiles(ACCOUNT_NAME), () => ReadAccountProfiles(ACCOUNT_NAME));
     AccountCollection.GetOrCreate(ACCOUNT_NAME).Profiles.Count().Should(Be.EqualTo(1));
 }