Assert Method was called, with a list of Object as an argument?

Skip to first unread message


Jan 2, 2014, 3:50:44 PM1/2/14
private readonly IQueryable<Setting> SaveDbSettings = new List<Setting>
                new Setting {Key = SomethingKey, SettingTypeID = (int) AppType, Value = HostVal},
                new Setting {Key = ShowSomethingKey, SettingTypeID = (int) AppType, Value = ShowSomethingValue},
                new Setting {Key = KeyBitLengthKey, SettingTypeID = (int)AppType, Value = KeyBitLengthValue}
private void SetupSaveSettingsModel()
            AutoMocker.Get<IRepository<Setting>>().Stub(x => x.All()).Return(SaveDbSettings);
                .Stub(x => x.AddToCache(SettingsCachePrefix + AppType, SaveDbSettings.Where(y => y.SettingTypeID == (int)AppType).ToList()));
                .Stub(x => x.GetListFromCache(SettingsCachePrefix + AppType))
                .Return(SaveDbSettings.Where(y => y.SettingTypeID == (int)AppType).ToList());
        public void SaveSettings_ShouldUpdateSettingsViaAddCollection()


            //AutoMocker.Get<IRepository<Setting>>().AssertWasCalled(x => x.UpdateCollection(Arg<IQueryable<Setting>>.List.Element(0, Property.Value("Key", HostKey))));
            AutoMocker.Get<IRepository<Setting>>().AssertWasCalled(x => x.UpdateCollection(SaveDbSettings), opt => opt.IgnoreArguments());

What is the syntax for getting this to pass? Unless I IgnoreArguments() it fails, I'm assuming the List<Object> are not truly equal somehow. So I tried to the commented out line, but to no avail. I'm pretty lost on what I should be doing under this pattern, but it's pretty important because the guy who wrote our repository layer didn't add any code for saving lists, so we'd have to go _serviceLayer.Save(singleObject) like 20 times just to "save a collection". Our unit tests contain no examples of how you assert than a method like this is actually called, and get it to pass WITHOUT IgnoreArguments(). I'm trying to add that to our codebase, but it's been giving me fits. Any tips? Much appreciated.

Mike Meisinger

Mar 24, 2014, 8:31:09 PM3/24/14
While I haven't seen that exact type of problem, I am familiar with there being limitations to how the Arg Constraints work. When that happens to me I will use the Get Arguments For Calls Made On extension method using the Arg (of type) IsAnything as the arguments.

From there an array of calls are retuned which contain an array of arguments. I can then iterate through the calls and arguments asserting my expectation.

Hope that helps

Reply all
Reply to author
0 new messages