public async Task InsertRandomData() { //Arrange var dbSet = Substitute.For <DbSet <DefaultModel> >(); var context = Substitute.For <DefaultContext>(); context.DefaultModels = dbSet; var controller = new DefaultController(context); //Act await controller.GenerateData(); //Assert dbSet.Received(1).Add(Arg.Any <DefaultModel>()); await context.Received(1).SaveChangesAsync(); }