Skip to content

Commit

Permalink
test fixes, session fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dlmelendez committed Nov 17, 2019
1 parent b634959 commit 38f2a68
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<PackageReference Include="Microsoft.AspNet.Identity.Core" Version="2.2.2" />
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
<PackageReference Include="Microsoft.Azure.DocumentDB" Version="1.13.1" />
<PackageReference Include="Microsoft.Azure.DocumentDB" Version="1.13.4" />

</ItemGroup>
<ItemGroup>
Expand Down
103 changes: 50 additions & 53 deletions src/identity.documentdb/IdentityCloudContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,59 +129,51 @@ private void InitDatabase(string database)
}

private void InitCollections()
{
Task[] tasks = new Task[2] {
new TaskFactory().StartNew(() =>
{

_userDocumentCollection.IndexingPolicy.IndexingMode = IndexingMode.Lazy;
_userDocumentCollection.IndexingPolicy.IncludedPaths.Add(new IncludedPath()
{
Path = @"/",
Indexes= new Collection<Index>
{
new HashIndex(DataType.String)
}
});
_userDocumentCollection.IndexingPolicy.IncludedPaths.Add(new IncludedPath()
{
Path = @"/""Email""/?",
Indexes= new Collection<Index>
{
new HashIndex(DataType.String)
}
});
_userDocumentCollection.IndexingPolicy.IncludedPaths.Add(new IncludedPath()
{
Path = @"/""UserName""/?",
Indexes= new Collection<Index>
{
new HashIndex(DataType.String)
}
});
_userDocumentCollection.IndexingPolicy.IncludedPaths.Add(new IncludedPath()
{
Path = @"/""UserId""/?",
Indexes= new Collection<Index>
{
new HashIndex(DataType.String)
}
});

var ucTask = _client.CreateDocumentCollectionIfNotExistsAsync(_db.SelfLink, _userDocumentCollection);
ucTask.Wait();
var uc = ucTask.Result;
UserDocumentCollection = uc;
}),
new TaskFactory().StartNew(() =>
{
var rcTask = _client.CreateDocumentCollectionIfNotExistsAsync(_db.SelfLink, _roleDocumentCollection);
rcTask.Wait();
var rc = rcTask.Result;
RoleDocumentCollection = rc;
})
};
Task.WaitAll(tasks);
{
_userDocumentCollection.IndexingPolicy.IndexingMode = IndexingMode.Lazy;
_userDocumentCollection.IndexingPolicy.IncludedPaths.Add(new IncludedPath()
{
Path = @"/",
Indexes= new Collection<Index>
{
new HashIndex(DataType.String)
}
});
_userDocumentCollection.IndexingPolicy.IncludedPaths.Add(new IncludedPath()
{
Path = @"/""Email""/?",
Indexes= new Collection<Index>
{
new HashIndex(DataType.String)
}
});
_userDocumentCollection.IndexingPolicy.IncludedPaths.Add(new IncludedPath()
{
Path = @"/""UserName""/?",
Indexes= new Collection<Index>
{
new HashIndex(DataType.String)
}
});
_userDocumentCollection.IndexingPolicy.IncludedPaths.Add(new IncludedPath()
{
Path = @"/""UserId""/?",
Indexes= new Collection<Index>
{
new HashIndex(DataType.String)
}
});

var ucTask = _client.CreateDocumentCollectionIfNotExistsAsync(_db.SelfLink, _userDocumentCollection);
ucTask.Wait();
var uc = ucTask.Result;
UserDocumentCollection = uc;

var rcTask = _client.CreateDocumentCollectionIfNotExistsAsync(_db.SelfLink, _roleDocumentCollection);
rcTask.Wait();
var rc = rcTask.Result;
RoleDocumentCollection = rc;

}

private void InitStoredProcs()
Expand Down Expand Up @@ -365,6 +357,11 @@ public void SetSessionTokenIfEmpty(string tokenNew)
}
}

public void SetSessionToken(string tokenNew)
{
_sessionToken = tokenNew;
}

public DocumentCollection RoleDocumentCollection
{
get { ThrowIfDisposed(); return _roleDocumentCollection; }
Expand Down
6 changes: 3 additions & 3 deletions src/identity.documentdb/UserStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public async virtual Task CreateAsync(TUser user)

var doc = await Context.Client.CreateDocumentAsync(Context.UserDocumentCollection.DocumentsLink, user
, Context.RequestOptions, true);
Context.SetSessionTokenIfEmpty(doc.SessionToken);
Context.SetSessionToken(doc.SessionToken);
JsonConvert.PopulateObject(doc.Resource.ToString(), user);

}
Expand All @@ -173,7 +173,7 @@ public async virtual Task DeleteAsync(TUser user)

var result = await Context.Client.DeleteDocumentAsync(user.SelfLink,
Context.RequestOptions);
Context.SetSessionTokenIfEmpty(result.SessionToken);
Context.SetSessionToken(result.SessionToken);

}

Expand Down Expand Up @@ -639,7 +639,7 @@ public async virtual Task UpdateAsync(TUser user)

var result = await Context.Client.ReplaceDocumentAsync(user.SelfLink, user,
Context.RequestOptions);
Context.SetSessionTokenIfEmpty(result.SessionToken);
Context.SetSessionToken(result.SessionToken);
user = Activator.CreateInstance<TUser>();
JsonConvert.PopulateObject(result.Resource.ToString(), user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageReference Include="Microsoft.AspNet.Identity.Core" Version="2.2.2" />
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
<PackageReference Include="Microsoft.Azure.DocumentDB" Version="1.13.1" />
<PackageReference Include="Microsoft.Azure.DocumentDB" Version="1.13.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
Expand Down
7 changes: 4 additions & 3 deletions tests/identity.documentdb.tests/RoleStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Linq;
using System.Threading;
using System.Configuration;
using System.Threading.Tasks;

namespace ElCamino.AspNet.Identity.DocumentDB.Tests
{
Expand Down Expand Up @@ -78,9 +79,9 @@ public void CreateRoleScratch()

[TestMethod]
[TestCategory("Identity.Azure.RoleStore")]
public void CreateRoleSameCollection()
public async Task CreateRoleSameCollection()
{
const string sameCol = "same";
const string sameCol = "ur";
//var ic = new IdentityCloudContext<IdentityUser>(sameCol, sameCol);

using (RoleStore<IdentityRole> store = new RoleStore<IdentityRole>(new IdentityCloudContext(sameCol, sameCol)))
Expand All @@ -91,7 +92,7 @@ public void CreateRoleSameCollection()
var role = CreateRoleHelper(manager);
WriteLineObject<IdentityRole>(role);

var result = store.Context.Client.DeleteDocumentCollectionAsync(store.Context.UserDocumentCollection.SelfLink).Result;
var result = await store.Context.Client.DeleteDocumentCollectionAsync(store.Context.UserDocumentCollection.SelfLink);

}
}
Expand Down
Loading

0 comments on commit 38f2a68

Please sign in to comment.