Skip to content

Commit 9e19e53

Browse files
committed
Fixing how we resolve MongoDB property names - consistently using _id for id fields
1 parent 6e4b038 commit 9e19e53

17 files changed

+272
-69
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Cratis. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Cratis.Chronicle.Properties;
5+
6+
namespace Cratis.Chronicle.Storage.MongoDB.for_PropertyExtensions.when_converting_to_mongo_db;
7+
8+
public class with_array_and_child_property : Specification
9+
{
10+
PropertyPath _propertyPath;
11+
string _result;
12+
13+
void Establish() => _propertyPath = new PropertyPath("[Configurations].ConfigurationId");
14+
15+
void Because() => _result = _propertyPath.ToMongoDB();
16+
17+
[Fact] void should_remove_brackets_and_preserve_casing() => _result.ShouldEqual("Configurations.ConfigurationId");
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Cratis. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Cratis.Chronicle.Properties;
5+
6+
namespace Cratis.Chronicle.Storage.MongoDB.for_PropertyExtensions.when_converting_to_mongo_db;
7+
8+
public class with_array_and_id_child_property : Specification
9+
{
10+
PropertyPath _propertyPath;
11+
string _result;
12+
13+
void Establish() => _propertyPath = new PropertyPath("[Configurations].Id");
14+
15+
void Because() => _result = _propertyPath.ToMongoDB();
16+
17+
[Fact] void should_convert_id_to_underscore_id() => _result.ShouldEqual("Configurations._id");
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Cratis. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Cratis.Chronicle.Properties;
5+
6+
namespace Cratis.Chronicle.Storage.MongoDB.for_PropertyExtensions.when_converting_to_mongo_db;
7+
8+
public class with_array_property : Specification
9+
{
10+
PropertyPath _propertyPath;
11+
string _result;
12+
13+
void Establish() => _propertyPath = new PropertyPath("[Configurations]");
14+
15+
void Because() => _result = _propertyPath.ToMongoDB();
16+
17+
[Fact] void should_remove_brackets_and_preserve_casing() => _result.ShouldEqual("Configurations");
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Cratis. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Cratis.Chronicle.Properties;
5+
6+
namespace Cratis.Chronicle.Storage.MongoDB.for_PropertyExtensions.when_converting_to_mongo_db;
7+
8+
public class with_complex_path : Specification
9+
{
10+
PropertyPath _propertyPath;
11+
string _result;
12+
13+
void Establish() => _propertyPath = new PropertyPath("Organization.[Departments].[Employees].FirstName");
14+
15+
void Because() => _result = _propertyPath.ToMongoDB();
16+
17+
[Fact] void should_convert_entire_path_correctly() => _result.ShouldEqual("Organization.Departments.Employees.FirstName");
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Cratis. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Cratis.Chronicle.Properties;
5+
6+
namespace Cratis.Chronicle.Storage.MongoDB.for_PropertyExtensions.when_converting_to_mongo_db;
7+
8+
public class with_deeply_nested_path_with_id : Specification
9+
{
10+
PropertyPath _propertyPath;
11+
string _result;
12+
13+
void Establish() => _propertyPath = new PropertyPath("[Configurations].[Hubs].Id");
14+
15+
void Because() => _result = _propertyPath.ToMongoDB();
16+
17+
[Fact] void should_convert_id_to_underscore_id() => _result.ShouldEqual("Configurations.Hubs._id");
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Cratis. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Cratis.Chronicle.Properties;
5+
6+
namespace Cratis.Chronicle.Storage.MongoDB.for_PropertyExtensions.when_converting_to_mongo_db;
7+
8+
public class with_id_property : Specification
9+
{
10+
PropertyPath _propertyPath;
11+
string _result;
12+
13+
void Establish() => _propertyPath = new PropertyPath("Id");
14+
15+
void Because() => _result = _propertyPath.ToMongoDB();
16+
17+
[Fact] void should_return_underscore_id() => _result.ShouldEqual("_id");
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Cratis. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Cratis.Chronicle.Properties;
5+
6+
namespace Cratis.Chronicle.Storage.MongoDB.for_PropertyExtensions.when_converting_to_mongo_db;
7+
8+
public class with_lowercase_id_property : Specification
9+
{
10+
PropertyPath _propertyPath;
11+
string _result;
12+
13+
void Establish() => _propertyPath = new PropertyPath("id");
14+
15+
void Because() => _result = _propertyPath.ToMongoDB();
16+
17+
[Fact] void should_return_underscore_id() => _result.ShouldEqual("_id");
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Cratis. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Cratis.Chronicle.Properties;
5+
6+
namespace Cratis.Chronicle.Storage.MongoDB.for_PropertyExtensions.when_converting_to_mongo_db;
7+
8+
public class with_nested_arrays : Specification
9+
{
10+
PropertyPath _propertyPath;
11+
string _result;
12+
13+
void Establish() => _propertyPath = new PropertyPath("[Configurations].[Hubs].Name");
14+
15+
void Because() => _result = _propertyPath.ToMongoDB();
16+
17+
[Fact] void should_remove_all_brackets_and_preserve_casing() => _result.ShouldEqual("Configurations.Hubs.Name");
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Cratis. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Cratis.Chronicle.Properties;
5+
6+
namespace Cratis.Chronicle.Storage.MongoDB.for_PropertyExtensions.when_converting_to_mongo_db;
7+
8+
public class with_nested_id_property : Specification
9+
{
10+
PropertyPath _propertyPath;
11+
string _result;
12+
13+
void Establish() => _propertyPath = new PropertyPath("User.Id");
14+
15+
void Because() => _result = _propertyPath.ToMongoDB();
16+
17+
[Fact] void should_convert_id_to_underscore_id() => _result.ShouldEqual("User._id");
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Cratis. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Cratis.Chronicle.Properties;
5+
6+
namespace Cratis.Chronicle.Storage.MongoDB.for_PropertyExtensions.when_converting_to_mongo_db;
7+
8+
public class with_nested_property : Specification
9+
{
10+
PropertyPath _propertyPath;
11+
string _result;
12+
13+
void Establish() => _propertyPath = new PropertyPath("User.FirstName");
14+
15+
void Because() => _result = _propertyPath.ToMongoDB();
16+
17+
[Fact] void should_preserve_original_casing() => _result.ShouldEqual("User.FirstName");
18+
}

0 commit comments

Comments
 (0)