You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

108 lines
3.4 KiB

/* Copyright 2010-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using FluentAssertions;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Serializers;
using Xunit;
namespace MongoDB.Driver.Tests
{
public class AggregateBucketAutoResultIdSerializerTests
{
[Fact]
public void Equals_derived_should_return_false()
{
var x = new AggregateBucketAutoResultIdSerializer<int>(Int32Serializer.Instance);
var y = new DerivedFromAggregateBucketAutoResultIdSerializer<int>(Int32Serializer.Instance);
var result = x.Equals(y);
result.Should().Be(false);
}
[Fact]
public void Equals_null_should_return_false()
{
var x = new AggregateBucketAutoResultIdSerializer<int>(Int32Serializer.Instance);
var result = x.Equals(null);
result.Should().Be(false);
}
[Fact]
public void Equals_object_should_return_false()
{
var x = new AggregateBucketAutoResultIdSerializer<int>(Int32Serializer.Instance);
var y = new object();
var result = x.Equals(y);
result.Should().Be(false);
}
[Fact]
public void Equals_self_should_return_true()
{
var x = new AggregateBucketAutoResultIdSerializer<int>(Int32Serializer.Instance);
var result = x.Equals(x);
result.Should().Be(true);
}
[Fact]
public void Equals_with_equal_fields_should_return_true()
{
var x = new AggregateBucketAutoResultIdSerializer<int>(Int32Serializer.Instance);
var y = new AggregateBucketAutoResultIdSerializer<int>(Int32Serializer.Instance);
var result = x.Equals(y);
result.Should().Be(true);
}
[Fact]
public void Equals_with_not_equal_field_should_return_false()
{
var valueSerializer1 = new Int32Serializer(Bson.BsonType.Int32);
var valueSerializer2 = new Int32Serializer(Bson.BsonType.String);
var x = new AggregateBucketAutoResultIdSerializer<int>(valueSerializer1);
var y = new AggregateBucketAutoResultIdSerializer<int>(valueSerializer2);
var result = x.Equals(y);
result.Should().Be(false);
}
[Fact]
public void GetHashCode_should_return_zero()
{
var x = new AggregateBucketAutoResultIdSerializer<int>(Int32Serializer.Instance);
var result = x.GetHashCode();
result.Should().Be(0);
}
public class DerivedFromAggregateBucketAutoResultIdSerializer<TValue> : AggregateBucketAutoResultIdSerializer<TValue>
{
public DerivedFromAggregateBucketAutoResultIdSerializer(IBsonSerializer<TValue> valueSerializer) : base(valueSerializer)
{
}
}
}
}