コード例 #1
0
        public async Task Handle_SaveWithResponse_CreatesUser()
        {
            var request = new SaveUserWithResponseRequest
            {
                Name = "TestUser"
            };

            var response = await Mediator.HandleAsync(request);

            Assert.IsFalse(response.HasErrors);
            Assert.AreEqual(1, Context.Set <User>().Count());
            Assert.IsNotNull(response.Data);
            Assert.AreEqual("TestUser", response.Data.Name);
        }
コード例 #2
0
        public async Task Handle_SaveExistingWithResponse_UpdatesUser()
        {
            var existing = new User {
                Name = "TestUser"
            };

            Context.Add(existing);

            await Context.SaveChangesAsync();

            var request = new SaveUserWithResponseRequest
            {
                Name = existing.Name
            };

            var response = await Mediator.HandleAsync(request);

            Assert.IsFalse(response.HasErrors);
            Assert.AreEqual(1, Context.Set <User>().Count());
            Assert.IsNotNull(response.Data);
            Assert.AreEqual("TestUser", response.Data.Name);
        }