public async Task Delete_Cat_Successful()
        {
            var cat = Cats.FirstOrDefault();

            cat.Name = Guid.NewGuid().ToString();

            await CatRepository.Delete(cat.Id);

            Cats.Remove(cat);

            var existingCat = await CatRepository.GetById(cat.Id);

            existingCat.Should().BeNull();
        }
Ejemplo n.º 2
0
        public void OneTimeSetUp()
        {
            Setup.Bootstrap(SetupType.Test);

            CreateCatTestData();

            var mockApiClient  = new Mock <IApiClient>();
            var mockServiceBus = new Mock <IMessageBroker <Cat> >();
            var mockCatService = new Mock <ICatService>();

            // Setup the cat service
            mockCatService.Setup(x => x.GetAll()).Returns(Task.FromResult(Cats.AsEnumerable()));

            mockCatService.Setup(x => x.GetById(It.IsAny <Guid>()))
            .Returns((Guid id) => { return(Task.FromResult(Cats.FirstOrDefault(x => x.Id == id))); });

            mockCatService.Setup(x => x.Create(It.IsAny <Cat>()))
            .Returns((Cat entity) =>
            {
                Cats.Add(entity);

                return(Task.CompletedTask);
            });

            mockCatService.Setup(x => x.Update(It.IsAny <Cat>()))
            .Returns((Cat entity) =>
            {
                var existing = Cats.Find(x => x.Id == entity.Id);

                Cats.Remove(existing);
                Cats.Add(entity);

                return(Task.CompletedTask);
            });

            mockCatService.Setup(x => x.Delete(It.IsAny <Guid>()))
            .Returns((Guid id) =>
            {
                Cats.Remove(Cats.FirstOrDefault(x => x.Id == id));
                return(Task.CompletedTask);
            });

            ApiClient     = mockApiClient.Object;
            MessageBroker = mockServiceBus.Object;
            CatService    = mockCatService.Object;

            ViewModel = new MainViewModel(CatService);
        }