Skip to content

Commit 40d1c9a

Browse files
committed
getting rid of key generator because class as key is more elegant.
1 parent 125fc39 commit 40d1c9a

File tree

5 files changed

+35
-123
lines changed

5 files changed

+35
-123
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace TableStorage.Abstractions.POCO.Tests
2+
{
3+
public partial class PocoTableStoreTests
4+
{
5+
public class PartitionKey
6+
{
7+
public PartitionKey(int companyId, int departmentId)
8+
{
9+
CompanyId = companyId;
10+
DepartmentId = departmentId;
11+
}
12+
public int CompanyId { get; }
13+
public int DepartmentId { get; }
14+
}
15+
16+
}
17+
}

src/TableStorage.Abstractions.POCO.Tests/PocoTableStoreTests.cs

Lines changed: 17 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace TableStorage.Abstractions.POCO.Tests
88
{
99
[TestClass]
10-
public class PocoTableStoreTests
10+
public partial class PocoTableStoreTests
1111
{
1212
private PocoTableStore<Employee, int, int> tableStore;
1313

@@ -1321,50 +1321,6 @@ public void update_record_with_calculated_partition_key_from_multiple_properties
13211321

13221322
}
13231323

1324-
[TestMethod]
1325-
public void get_record_with_calculated_partition_key_from_multiple_properties_using_extension_method()
1326-
{
1327-
KeyGenerator.DefineParitionKey(typeof(Employee), e=>$"{e.CompanyId}.{e.DepartmentId}");
1328-
KeyGenerator.DefineRowKey(typeof(Employee), e => $"{e.Id}");
1329-
1330-
var pKeyMapper = new KeyMapper<Employee, int>(e => $"{e.CompanyId}.{e.Department.Id}", null, null, null);
1331-
var rKeyMapper = new KeyMapper<Employee, int>(e => e.Id.ToString(), int.Parse, e => e.Id,
1332-
id => id.ToString());
1333-
1334-
var tableConverter = new CalculatedKeysTableConverter<Employee, int, int>(pKeyMapper, rKeyMapper);
1335-
1336-
tableStore = new PocoTableStore<Employee, int, int>("TestEmployee", "UseDevelopmentStorage=true", tableConverter);
1337-
1338-
1339-
var employee = new Employee
1340-
{
1341-
CompanyId = 1,
1342-
Id = 1,
1343-
Name = "Mr. Jim CEO",
1344-
Department = new Department { Id = 22, Name = "Executive" }
1345-
};
1346-
tableStore.Insert(employee);
1347-
1348-
var record = tableStore.GetRecord(KeyGenerator.PartitionKey<Employee>(new {CompanyId=1, DepartmentId=22}),
1349-
KeyGenerator.RowKey<Employee>(new { Id = 1 }));
1350-
1351-
Assert.AreEqual(1, record.Id);
1352-
Assert.AreEqual(22, record.Department.Id);
1353-
Assert.AreEqual("Mr. Jim CEO", record.Name);
1354-
1355-
}
1356-
1357-
public class PartitionKey
1358-
{
1359-
public PartitionKey(int companyId, int departmentId)
1360-
{
1361-
CompanyId = companyId;
1362-
DepartmentId = departmentId;
1363-
}
1364-
public int CompanyId { get; }
1365-
public int DepartmentId { get; }
1366-
}
1367-
13681324

13691325
[TestMethod]
13701326
public void get_record_with_calculated_partition_key_from_multiple_properties_using_class_as_key()
@@ -1407,18 +1363,24 @@ public void get_record_with_calculated_partition_key_from_multiple_properties_us
14071363

14081364

14091365
[TestMethod]
1410-
public void update_record_with_calculated_partition_key_from_multiple_properties_using_extension_method()
1366+
public void update_record_with_calculated_partition_key_from_multiple_properties_using_class_as_key()
14111367
{
1412-
KeyGenerator.DefineParitionKey(typeof(Employee), e => $"{e.CompanyId}.{e.DepartmentId}");
1413-
KeyGenerator.DefineRowKey(typeof(Employee), e => $"{e.Id}");
14141368

1415-
var pKeyMapper = new KeyMapper<Employee, int>(e => $"{e.CompanyId}.{e.Department.Id}", null, null, null);
1369+
var pKeyMapper = new CalculatedKeyMapper<Employee, PartitionKey>(e => $"{e.CompanyId}.{e.Department.Id}", key =>
1370+
{
1371+
var parts = key.Split('.');
1372+
var companyId = int.Parse(parts[0]);
1373+
var departmentId = int.Parse(parts[1]);
1374+
return new PartitionKey(companyId, departmentId);
1375+
}, key => $"{key.CompanyId}.{key.DepartmentId}");
1376+
14161377
var rKeyMapper = new KeyMapper<Employee, int>(e => e.Id.ToString(), int.Parse, e => e.Id,
14171378
id => id.ToString());
14181379

1419-
var tableConverter = new CalculatedKeysTableConverter<Employee, int, int>(pKeyMapper, rKeyMapper);
14201380

1421-
tableStore = new PocoTableStore<Employee, int, int>("TestEmployee", "UseDevelopmentStorage=true", tableConverter);
1381+
var tableConverter = new CalculatedKeysTableConverter<Employee, PartitionKey, int>(pKeyMapper, rKeyMapper);
1382+
1383+
var tableStore2 = new PocoTableStore<Employee, PartitionKey, int>("TestEmployee", "UseDevelopmentStorage=true", tableConverter);
14221384

14231385

14241386
var employee = new Employee
@@ -1428,15 +1390,14 @@ public void update_record_with_calculated_partition_key_from_multiple_properties
14281390
Name = "Mr. Jim CEO",
14291391
Department = new Department { Id = 22, Name = "Executive" }
14301392
};
1431-
tableStore.Insert(employee);
1393+
tableStore2.Insert(employee);
14321394

14331395
employee.Name = "Ted";
14341396

1435-
tableStore.Update(employee);
1397+
tableStore2.Update(employee);
14361398

1437-
var record = tableStore.GetRecord(
1438-
KeyGenerator.PartitionKey<Employee>(new { CompanyId = 1, DepartmentId = 22 }),
1439-
KeyGenerator.RowKey<Employee>(new { Id = 1 }));
1399+
var record = tableStore2.GetRecord(
1400+
new PartitionKey(1,22), 1 );
14401401

14411402
Assert.AreEqual(1, record.Id);
14421403
Assert.AreEqual(22, record.Department.Id);

src/TableStorage.Abstractions.POCO.Tests/TableStorage.Abstractions.POCO.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<ItemGroup>
101101
<Compile Include="Department.cs" />
102102
<Compile Include="Employee.cs" />
103+
<Compile Include="PartitionKey.cs" />
103104
<Compile Include="PocoTableStoreTests.cs" />
104105
<Compile Include="Properties\AssemblyInfo.cs" />
105106
</ItemGroup>

src/TableStorage.Abstractions.POCO/KeyGenerator.cs

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/TableStorage.Abstractions.POCO/TableStorage.Abstractions.POCO.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
<Compile Include="CalculatedKeyMapper.cs" />
9292
<Compile Include="CalculatedKeysTableConverter.cs" />
9393
<Compile Include="FixedKeyMapper.cs" />
94-
<Compile Include="KeyGenerator.cs" />
9594
<Compile Include="KeyMapper.cs" />
9695
<Compile Include="SimpleTableConverter.cs" />
9796
<Compile Include="ITableConverter.cs" />

0 commit comments

Comments
 (0)