Discussions
Verification of list parameters
I'm trying to verify a call was made to a repository AddRange method. I can verify the method was called at all like this:
GetMockFor<IThingRepository>()
.Verify(x => x.AddRange(It.IsAny<IEnumerable<Thing>>()), Times.Once);
I can verify that it was passed the expected two objects using some of Moq's partial matching like this:
GetMockFor<IThingRepository>()
.Verify(x => x.AddRange(It.Is<IEnumerable<Thing>>(y =>
y.Count() == 2
&& y.Any(z => z.ThingType == ThingType.Foo)
&& y.Any(z => z.ThingType == ThingType.Bar))));
What I can't seem to do is get it to work using a more understandable partial matching syntax like this:
GetMockFor<IThingRepository>()
.Verify(x => x.AddRange(Looks.Like(() => new[]
{
new Thing {ThingType = ThingType.Foo},
new Thing {ThingType = ThingType.Bar},
})));
In every case, the code runs but the verify fails saying the method was never called. I looked through the documentation examples, and while they cover the partial matching functionality, they don't have an example of partial matching a collection of things like this. I know the partial matching can do hierarchies, but what about collections?
I've even tried replacing the objects in the list with their own individual Looks.Likes:
GetMockFor<IThingRepository>()
.Verify(x => x.AddRange(
Looks.Like(() => new[]
{
Looks.Like(()=>new Thing {ThingType = ThingType.Foo}),
Looks.Like(()=>new Thing {ThingType = ThingType.Bar}),
})));
Because of the way this particular code is written, the order of the elements being added is predictable, so I've eliminated that variable, although a partial match that could ignore ordering would be pretty awesome.
What am I doing wrong here?
Interesting. I built a spec based on your description:
[Test]
public void then_it_matches_on_equivalent_enumerables()
{
var mock = GetMockFor<ITestService>();
mock.Object.AddRange(new[]
{
new TestObject { ID = 1, Name = "Test 1" },
new TestObject { ID = 2, Name = "Test 2" },
});
Assert.DoesNotThrow(() => mock.Verify(s => s.AddRange(Looks.Like(() => new[]
{
new TestObject { ID = 1, Name = "Test 1" },
new TestObject { ID = 2, Name = "Test 2" },
}))));
}
That spec passes.
Here's the definition of ITestService:
public interface ITestService
{
void AddRange(IEnumerable<TestObject> testObjects);
}
However, I can break the spec if I instead call it with a List:
[Test]
public void then_it_matches_on_equivalent_enumerables()
{
var mock = GetMockFor<ITestService>();
var items = new List<TestObject>
{
new TestObject {ID = 1, Name = "Test 1"},
new TestObject {ID = 2, Name = "Test 2"},
};
mock.Object.AddRange(items);
Assert.DoesNotThrow(() => mock.Verify(s => s.AddRange(Looks.Like(() => new[]
{
new TestObject { ID = 1, Name = "Test 1" },
new TestObject { ID = 2, Name = "Test 2" },
}))));
}
Are you calling AddRange with an array, or a something else?
In any case, this seems to be a bug in Looks.Like(), I just need to figure out the exact scenario so I can fix it.
Aha, that's it. AddRange is being passed an IEnumerable which is the result of an EF/Linq query, so it's technically and ObjectSet at that point. I can see that throwing off the Looks.Like since the two enumerables are not the same type.
It would be acceptable to call ToArray or ToList on the collection before calling AddRange, since it will enumerate at that point anyway. I just tested it this way, and now the test works.
So the scenario is that Looks.Like sees an array on the one side, an ObjectSet on the other, and decides that they're dissimilar enough to call it quits right then. I don't know what's going on behind the scenes here, but unless Looks.Like has some way to figure out that the method being called wanted any kind of IEnumerable, and can take that into account when comparing the two objects, I'd say this is a matter for documentation rather than code.
Thanks.
I'd like to make the partial matching handle this better. It should already know that both ends of the call are compatible enumerables since the compiler will enforce that. At the very least, it should throw a more useful exception.
I've opened up a Github issue for this, and I'll address it the next time I'm working on the code: https://github.com/MattHoneycutt/SpecsFor/issues/91
I'd like to make the partial matching handle this better. It should already know that both ends of the call are compatible enumerables since the compiler will enforce that. At the very least, it should throw a more useful exception.
I've opened up a Github issue for this, and I'll address it the next time I'm working on the code: https://github.com/MattHoneycutt/SpecsFor/issues/91
- https://seofox.ir/seo-principles/
- https://seofox.ir/seo-checklist/
- https://seofox.ir/seo/
- https://seofox.ir/seo-contract/
- https://seofox.ir/
- https://seofox.ir/gray-hat-seo/
- https://seofox.ir/robots/
- https://seofox.ir/link-farm-and-content-farm/
- https://seofox.ir/keyword-density/
- https://seofox.ir/search-engine/
- https://seofox.ir/backlink/
- https://seofox.ir/analyze-seo/
- https://seofox.ir/page-rank/
- https://seofox.ir/proposal/
- https://seofox.ir/white-hat-seo/
- https://seofox.ir/ugc-keyword-research/
- https://seofox.ir/backlink-definition/
- https://seofox.ir/seo-company/
- https://seofox.ir/googlebot/
- https://seofox.ir/page-speed/
- https://seofox.ir/broken-link/
- https://seofox.ir/seo-techniques/
- https://seofox.ir/meta-description/
- https://seofox.ir/ctr/
- https://seofox.ir/sandbox/
- https://seofox.ir/anchor-text/
- https://seofox.ir/rankbrain/
- https://seofox.ir/long-tail-keywords/
- https://seofox.ir/google-panda/
- https://seofox.ir/page-title/
- https://seofox.ir/content-marketing/
- https://seofox.ir/order/
- https://seofox.ir/redirect/
- https://seofox.ir/technical-seo/
- https://seofox.ir/on-page-seo/
- https://seofox.ir/seo-tools/
- https://seofox.ir/branding/
- https://seofox.ir/link-building/
- https://seofox.ir/off-page-seo/
- https://seofox.ir/seo-consultation/
- https://seofox.ir/on-page-seo/
- https://seofox.ir/local-seo/
- https://seofox.ir/wordpress-seo-plugin/
- https://seofox.ir/seo-services-prices/
- https://seofox.ir/google-seo-book/
- https://seofox.ir/start-seo/
- https://seofox.ir/seo-periodic-table/
- https://seofox.ir/content-vs-link/
- https://seofox.ir/social-marketing/
- https://seofox.ir/serpmojo/
- https://seofox.ir/spam-links-disavow/
- https://seofox.ir/google-penalty-removal/
- https://seofox.ir/h1/
- https://seofox.ir/google-penguin/
- https://seofox.ir/seo-articels/
- https://seofox.ir/what-is-google-dance/
- https://seofox.ir/bing/
- https://seofox.ir/rules-of-link-building/
- https://seofox.ir/seo-news/
- https://seofox.ir/what-is-domain-authority-and-page-authority/
- https://seofox.ir/template/
- https://seofox.ir/what-is-content-marketing/
- https://seofox.ir/host/
- https://seofox.ir/add-site-in-google/
- https://seofox.ir/domain-seo/
- https://seofox.ir/nofollow-links/
- https://seofox.ir/seo-portfolio/
- https://seofox.ir/contact-us/
- https://seofox.ir/faq/
- https://seofox.ir/privacy-policy/
- https://seofox.ir/terms/
- https://seofox.ir/about-us/
- https://seofox.ir/category/google-algorithms/
- https://seofox.ir/category/backlink/
- https://seofox.ir/category/blog/
- https://seofox.ir/category/services/
- https://seofox.ir/category/seo/
- https://seofox.ir/category/seo-content/
- https://seofox.ir/category/seo-resources/
- https://seofox.ir/category/search-engine/
- https://seofox.ir/seo-training/
- https://seofox.ir/seo-services/
- https://seofox.ir/faq/
- https://seofox.ir/contact-us/
- https://seofox.ir/about-us/
- https://seofox.ir/privacy-policy/
- https://seofox.ir/terms/
تعریف سئو چیست؟ آموزش SEO - بهینه سازی موتور جستجو
تعریف سئو چیست؟ آموزش SEO - بهینه سازی موتور جستجو
تعریف سئو چیست؟ آموزش SEO - بهینه سازی موتور جستجو
تعریف سئو چیست؟ آموزش SEO - بهینه سازی موتور جستجو
تعریف سئو چیست؟ آموزش SEO - بهینه سازی موتور جستجو
تعریف سئو چیست؟ آموزش SEO - بهینه سازی موتور جستجو
5
Metin2 Pvp Serverler, yıllardır MMORPG dünyasında popülerliğini koruyan, aksiyon dolu savaş mekaniği ve etkileyici atmosferiyle oyuncuların ilgisini çeken bir oyundur. Ancak, resmi sunucuların belirli kurallar ve yavaş ilerleyen gelişim süreçleri bazı oyuncular için zaman zaman tatmin edici olmayabilir. İşte tam da bu noktada Metin2 Pvp Serverleri devreye girer.
Metin2 Pvp Serverler Nedir?
Metin2 Pvp Serverler, oyuncuların daha hızlı gelişim gösterebildiği, rekabetin ön planda olduğu ve çeşitli özel içeriklerin bulunduğu özel sunuculardır. Bu sunucular, genellikle resmi sunuculara kıyasla daha özgün bir oyun deneyimi sunar ve oyuncuların hızlıca güçlü karakterler oluşturmasına olanak tanır.
Metin2 Pvp Serverlerinin Avantajları
Hızlı Gelişim: Resmi sunucularda uzun süren seviye atlama süreci, PVP serverlerde hızlandırılmış deneyim puanı (EXP) ve daha yüksek droplarla daha kısa sürede tamamlanabilir.
Özel Eşyalar ve Sistemler: Çoğu Metin2 PVP sunucusu, oyuncuların ilgisini çekmek için özel itemler, etkinlikler ve benzersiz görevler sunar.
Dengeli PVP Sistemi: Metin2 PVP serverlerinde savaş sistemi genellikle dengeye oturtulmuştur. Böylece tüm oyuncuların rekabeti adil bir şekilde deneyimlemesi sağlanır.
Etkinlikler ve Turnuvalar: Düzenli olarak yapılan turnuvalar ve etkinlikler sayesinde oyuncular ödüller kazanabilir ve eğlenceli vakit geçirebilir.
agario is one of the most popular multiplayer browser games, offering simple yet highly addictive gameplay. However, many schools, workplaces, and institutions block access to gaming websites, preventing players from enjoying the game during breaks. This is where agario Unblocked comes in, allowing players to bypass restrictions and experience the game freely. agario online
What is agario unblocked?
agario unblocked is an online multiplayer game where players control a cell and consume smaller cells to grow larger while avoiding being eaten by bigger ones. The game is easy to understand but requires strategy, quick reflexes, and patience to dominate the leaderboard. io games
Why is agario Blocked?
Many schools and workplaces restrict access to gaming websites to maintain productivity. This is done using network filters that prevent users from opening specific gaming domains. However, for students and employees who want to relax during free time, these restrictions can be frustrating. Retro Bowl Unblocked
blogamca, bilgi edinmenin ve hayal gücünü geliştirmenin en önemli yollarından biridir. Ancak zaman zaman uzun kitapları okumak için yeterli vaktimiz olmayabilir. Bu noktada devreye kitap özetleri girer. arabuloku, temel bilgileri ve ana fikirleri sunarak okuyucuların zamandan tasarruf etmesine yardımcı olur.Okey Oyna