public void Return_default_if_no_item_exists() { var sample = new MySampleValue(); var dict = new Dictionary <int, MySampleValue> { { 100, sample } }; var theValue = dict.GetOrDefault(200); dict.Should().HaveCount(1).And.Contain(100, sample); theValue.Should().BeNull(); }
public void Return_existing_item_if_it_exists_not_default() { var sample = new MySampleValue(); var dict = new Dictionary <int, MySampleValue> { { 100, sample } }; var theValue = dict.GetOrDefault(100); // Ensure the container hasn't been mutated dict.Should().HaveCount(1).And.Contain(100, sample); theValue.Should().Be(sample); }
public void Return_existing_item_if_exists_not_create() { var sample = new MySampleValue(); var dict = new Dictionary <int, MySampleValue> { { 100, sample } }; var theValue = dict.GetOrCreate(100); dict.Should().HaveCount(1); dict.Should().Contain(100, sample); dict.Should().ContainValue(theValue); theValue.Should().Be(sample); }
private Resource GetSampleResource(MySampleValue sampleValue, IEnumerable <string> onlyFields = null) { return(CreateResource(GetUriFromRoute("getbyid", new { id = sampleValue.Id })) .AddLink("parent", GetUriFromRoute("getallvalues")) .Merge(sampleValue, onlyFields)); }