public void CheckIfAddPlayMethodDoesNotAddPlayToTheSameUserThatRequested()
        {
            // Arrange
            var plays    = new List <Play>();
            var beats    = new List <Beat>();
            var beatRepo = new Mock <IDeletableEntityRepository <Beat> >();

            beatRepo.Setup(b => b.AddAsync(It.IsAny <Beat>())).Callback(
                (Beat beat) => beats.Add(beat));
            beatRepo.Setup(b => b.All()).Returns(beats.AsQueryable());
            var playRepo = new Mock <IRepository <Play> >();

            playRepo.Setup(p => p.AddAsync(It.IsAny <Play>())).Callback(
                (Play play) => plays.Add(play));
            playRepo.Setup(r => r.All()).Returns(plays.AsQueryable());
            var likeRepo    = new Mock <IDeletableEntityRepository <Like> >();
            var beatService = new BeatService(beatRepo.Object, playRepo.Object, likeRepo.Object);

            // Act
            beatService.CreateAsync("test", "test", "test", 10, Genre.Rock.ToString(), 112, "test", "user").GetAwaiter();
            beatService.AddPlay(0, "user").GetAwaiter();

            // Assert
            Assert.Empty(plays);
        }
        public async Task CheckIfAllMethodReturnsTheCorrectAmountOfData(int?take = null, int skip = 0)
        {
            // Arrange
            var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext   = new ApplicationDbContext(optionsBuilder.Options);
            var beatRepo    = new EfDeletableEntityRepository <Beat>(dbContext);
            var playRepo    = new EfRepository <Play>(dbContext);
            var likeRepo    = new EfDeletableEntityRepository <Like>(dbContext);
            var beatService = new BeatService(beatRepo, playRepo, likeRepo);

            // Act
            for (int i = 1; i <= 100; i++)
            {
                var year = 2020;

                await beatRepo.AddAsync(new Beat
                {
                    Id        = i,
                    CreatedOn = DateTime.Parse($"13/02/{year++} 15:43:56"),
                });
            }
            await beatRepo.SaveChangesAsync();

            AutoMapperConfig.RegisterMappings(typeof(FakeBeatModel).Assembly);
            var result = await beatService.AllAsync <FakeBeatModel>(take, skip);

            dbContext.Database.EnsureDeleted();
            result.OrderBy(x => x.Id);

            // Assert
            Assert.Equal(take, result.ToList().Count);
            Assert.Equal(skip + 1, result.First().Id);
        }
        public void CheckIfUserCannotEditOtherUserBeat()
        {
            var plays    = new List <Play>();
            var beats    = new List <Beat>();
            var beatRepo = new Mock <IDeletableEntityRepository <Beat> >();

            beatRepo.Setup(b => b.AddAsync(It.IsAny <Beat>())).Callback(
                (Beat beat) => beats.Add(beat));
            beatRepo.Setup(b => b.All()).Returns(beats.AsQueryable());
            var playRepo    = new Mock <IRepository <Play> >();
            var likeRepo    = new Mock <IDeletableEntityRepository <Like> >();
            var beatService = new BeatService(beatRepo.Object, playRepo.Object, likeRepo.Object);

            beatService.CreateAsync("test", "test", "test", 10, Genre.Rock.ToString(), 112, "test", "user").GetAwaiter();
            beatService.UpdateAsync("anotherUser", 0, "hack", 100, Genre.HipHop.ToString(), 120, "hack").GetAwaiter();

            Assert.Equal("test", beats.First().Name);
        }
Example #4
0
 public BeatsController(BeatService beatService)
 {
     _beatService = beatService;
 }
 private void OnEnable()
 {
     instance = this;
 }