Example #1
0
        public void GuidStronglyTypedIdToDb(GuidStronglyTypedIdTestData inTestData)
        {
            // ToDo low priority localize the unit test's exception's message
            if (inTestData == null)
            {
                throw new ArgumentNullException(nameof(inTestData));
            }
            // Arrange
            // Start a transaction
            using (IDbTransaction dbTrans = DatabaseFixture.Db.OpenTransaction()) {
                // Act
                // Create a table in the database for a GuidStronglyTypedId
                // store the GuidStronglyTypedId object from the inTestData into the table
                DatabaseFixture.Db.Insert(inTestData.InstanceTestData);
                // Assert
                // Assert that the current row count for the table GuidStronglyTypedId is 1
                // Assert that the value of Id in the table's only row is the same as the object's value
                // Rollback the transaction
                dbTrans.Rollback();
            }

            // GUIDS are random, two sets of test data have fixed, non-random guids, the rest are random
            // if (inTestData.SerializedTestData.StartsWith("\"0000", System.StringComparison.InvariantCulture) || inTestData.SerializedTestData.StartsWith("\"01234", System.StringComparison.InvariantCulture)) {
            //   // DatabaseFixtureSystemTextJson.Serializer.Serialize(inTestData.InstanceTestData).Should().Be(inTestData.SerializedTestData);
            //   JsonSerializer.Serialize(inTestData.InstanceTestData, DatabaseFixture.JsonSerializerOptions).Should().Be(inTestData.SerializedTestData);
            // }
            // else {
            //   //DatabaseFixtureSystemTextJson.Serializer.Serialize(inTestData.InstanceTestData).Should().MatchRegex("^[0-9A-Fa-f]{8}-?([0-9A-Fa-f]{4}-?){3}[0-9A-Fa-f]{12}$");
            //   JsonSerializer.Serialize(inTestData.InstanceTestData, DatabaseFixture.JsonSerializerOptions).Should().MatchRegex("^\"[0-9A-Fa-f]{8}-?([0-9A-Fa-f]{4}-?){3}[0-9A-Fa-f]{12}\"$");
            // }
        }
 public void GuidStronglyTypedIdSerializeToJSON(GuidStronglyTypedIdTestData inTestData)
 {
     // ToDo low priority localize the unit test's exception's message
     if (inTestData == null)
     {
         throw new ArgumentNullException($"{nameof(inTestData)} argument should never be null");
     }
     // GUIDS are random, two sets of test data have fixed, non-random guids, the rest are random
     if (inTestData.SerializedTestData.StartsWith("\"0000", System.StringComparison.InvariantCulture) || inTestData.SerializedTestData.StartsWith("\"01234", System.StringComparison.InvariantCulture))
     {
         // SerializationSystemTextJsonFixture.Serializer.Serialize(inTestData.InstanceTestData).Should().Be(inTestData.SerializedTestData);
         JsonSerializer.Serialize(inTestData.InstanceTestData, SerializationFixture.JsonSerializerOptions).Should().Be(inTestData.SerializedTestData);
     }
     else
     {
         //SerializationSystemTextJsonFixture.Serializer.Serialize(inTestData.InstanceTestData).Should().MatchRegex("^[0-9A-Fa-f]{8}-?([0-9A-Fa-f]{4}-?){3}[0-9A-Fa-f]{12}$");
         JsonSerializer.Serialize(inTestData.InstanceTestData, SerializationFixture.JsonSerializerOptions).Should().MatchRegex("^\"[0-9A-Fa-f]{8}-?([0-9A-Fa-f]{4}-?){3}[0-9A-Fa-f]{12}\"$");
     }
 }
Example #3
0
 public void GuidStronglyTypedIdToDb(GuidStronglyTypedIdTestData inTestData)
 {
     // ToDo low priority localize the unit test's exception's message
     if (inTestData == null)
     {
         throw new ArgumentNullException(nameof(inTestData));
     }
     // Arrange
     // Start a transaction
     using (IDbTransaction dbTrans = DatabaseFixture.Db.OpenTransaction()) {
         // Act
         // Create a table in the database for a GuidStronglyTypedId
         // store the GuidStronglyTypedId object from the inTestData into the table
         DatabaseFixture.Db.Insert(inTestData.InstanceTestData);
         // Assert
         // Assert that the current row count for the table GuidStronglyTypedId is 1
         // Assert that the value of Id in the table's only row is the same as the object's value
         // Rollback the transaction
         dbTrans.Rollback();
     }
 }
 public void GuidStronglyTypedIdDeserializeFromJSON(GuidStronglyTypedIdTestData inTestData)
 {
     // ToDo low priority localize the unit test's exception's message
     if (inTestData == null)
     {
         throw new ArgumentNullException($"{nameof(inTestData)} argument should never be null");
     }
     if (String.IsNullOrEmpty(inTestData.SerializedTestData))
     {
         Action act = () => JsonSerializer.Deserialize <GuidStronglyTypedId>(inTestData.SerializedTestData, SerializationFixture.JsonSerializerOptions);
         act.Should().Throw <System.Text.Json.JsonException>()
         .WithMessage("The input does not contain any JSON tokens.*");
     }
     else if (inTestData.SerializedTestData.StartsWith("\"0000", System.StringComparison.InvariantCulture) || inTestData.SerializedTestData.StartsWith("\"01234", System.StringComparison.InvariantCulture))
     {
         //SerializationSystemTextJsonFixture.Serializer.Deserialize<GuidStronglyTypedId>(inTestData.SerializedTestData).Should().BeEquivalentTo(inTestData.InstanceTestData);
         var stronglyTypedId = JsonSerializer.Deserialize <GuidStronglyTypedId>(inTestData.SerializedTestData, SerializationFixture.JsonSerializerOptions);
         stronglyTypedId.Should().BeEquivalentTo(inTestData.InstanceTestData);
     }
     else
     {
         // ToDo: validate that strings that don't match a Guid throw an exception
     }
 }